Does EF Core ignore migrations file with old `product version`
See original GitHub issueI migrated my .NET Core 1.1 app over to .NET Core 2 and have issues with the ef db migration.
I noticed that the new migration I added when my app is running .NET Core 2 seems to not have knowledge of my .NET Core 1.1 migrations. Is this because the new file has a product version
of
.HasAnnotation("ProductVersion", "2.0.0-rtm-26452")
Where as my old ones were:
.HasAnnotation("ProductVersion", "1.1.2")
?
Issue Analytics
- State:
- Created 5 years ago
- Comments:22 (9 by maintainers)
Top Results From Across the Web
Does EF Core ignore migrations file with old product ...
The reason for the new EF to eliminate tables that do not exist and to create tables that already exist is in the...
Read more >Why does EF 6 ignore applied migrations if I move the ...
EF does already know where the migrations live. It tells me I can't add a new one because the old ones are still...
Read more >Managing Migrations - EF Core
You are free to move Migrations files and change their namespace manually. New migrations are created as siblings of the last migration.
Read more >Entity Framework Core Migrations
With migrations, you can easily apply or revert database changes as your application evolves, without losing existing data. EF Core Migrations ...
Read more >Migrations and Seed Data With Entity Framework Core
EF Core provides a method called Migrate to execute migration actions for us. All we have to do is to create model classes,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have a same problem when migrating my project from core 1.1 to core 2.1 and I found a solution that might help other developers who encountered the same problem.
The reason for the new EF to eliminate tables that do not exist and to create tables that already exist is in the old ForSqlServerToTable method. This method (deprecated in this version, overridden by the ToTable method) has generated this code in ModelSnapshot.cs:
The new ToTable method doesn`t create “b.HasAnnotation(“SqlServer:TableName”, “Roles”);” line and not recognizes this. In other words, the new implementation consider “AspNetRoles” as current table name and then attempts to change the AspNetRoles to Roles, for example.
For workaround this behavior, I change my ModelSnapshot class manualy, removing “b.HasAnnotation(“SqlServer:TableName”, “Roles”);” line, and change “b.ToTable(“AspNetRoles”);” to “b.ToTable(“Roles”);”.
Now my code looks like this:
That way, I was able to perform new migrations and the generated code did not want to drop and create tables.
@p2atran Probably the best way would be to scaffold a model from the database and compare the model created from that with the one that you have. (Probably easiest way to diff would be to add an empty migration after doing the scaffolding the model and then use the model snapshot file for the diff.)