Skip to content

Commit 79b0b85

Browse files
committed
Improve instructions on resetting migrations
Fixes #4273
1 parent 59a7000 commit 79b0b85

File tree

1 file changed

+10
-4
lines changed
  • entity-framework/core/managing-schemas/migrations

1 file changed

+10
-4
lines changed

entity-framework/core/managing-schemas/migrations/managing.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,16 @@ In some extreme cases, it may be necessary to remove all migrations and start ov
213213

214214
It's also possible to reset all migrations and create a single one without losing your data. This is sometimes called "squashing", and involves some manual work:
215215

216-
* Delete your **Migrations** folder
217-
* Create a new migration and generate a SQL script for it
218-
* In your database, delete all rows from the migrations history table
219-
* Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there. The insert SQL is the last operation in the SQL script generated above.
216+
1. Back up your database, in case something goes wrong.
217+
2. In your database, delete all rows from the migrations history table (e.g. `DELETE FROM [__EFMigrationsHistory]` on SQL Server).
218+
3. Delete your **Migrations** folder.
219+
4. Create a new migration and generate a SQL script for it (`dotnet ef migrations script`).
220+
5. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there. The insert SQL is the last operation in the SQL script generated above, and resembles the following (don't forget to update the values):
221+
222+
```sql
223+
INSERT INTO [__EFMigrationsHistory] ([MIGRATIONID], [PRODUCTVERSION])
224+
VALUES (N'<full_migration_timestamp_and_name>', N'<EF_version>');
225+
```
220226

221227
> [!WARNING]
222228
> Any [custom migration code](#customize-migration-code) will be lost when the **Migrations** folder is deleted. Any customizations must be applied to the new initial migration manually in order to be preserved.

0 commit comments

Comments
 (0)