EF Core Migrations - how to modify the previous migrations?

ef-core-2.0 ef-core-2.1 ef-core-2.2 ef-migrations entity-framework-core

Question

I have a question about editing migration files in EF Core.

Example: I have created 3 tables using separate migration for each: AddTable1, AddTable2, AddTable3.

After that several days later I decided to change the type of status column in Table1 to be int and not string.

After updating the AddTable1 migration file, deleting the database and executing update-database command the column was still defined with string type.

I noticed that all the .Designer.cs files still were using string type for status column despite my edit of Table1 migration file.

I copied the content of the AppDbContextModelSnapshot.cs file and manually updated all the .Designer.cs files for all migrations (note: the method name in source and .Designer.cs files is different).

And that helped. I'm sure that this is not the recommended way to use migrations.

My question is: is there a command which will do what I did - 'reset' the '.Designer.cs' files?

If not, how to make one? :)

1
0
7/10/2019 7:00:13 PM

Popular Answer

Think of migrations as Git commits. You don't rewrite previous commits once you've shared them with other team members (or in our case, applied a migration to a database). Instead, you create new migrations with additional changes.

If you haven't applied a migration or shared it with teammates, you can remove it and re-scaffold:

Remove-Migration
Add-Migration FixedUpMigration

See the EF Core Migrations docs for basic usage.

1
7/10/2019 9:09:51 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow