You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an old application in .Net Core 3.1 and EF Core 3.1. I have succesfully migrated to .net 8 and EF Core 8. The migrations folder was HUGE, so I reset the migrations, deleting all records in the [__EFMigrationsHistory] table and deleted the migration folder (the migrations folder is in a separate project.
I succesfully ran the initial migration and EF created the class with all existing tables, columns, indexes, etc. As the Database already exists, I manually added the migrations record to the [__EFMigrationsHistory] table.
I then had to add a new table. When I ran the Add-Migration, the resulting class is HUGE (should have only contained the necesarry code for the new table). It includes code for (i think) every column in the database, such as the following:
Any migration I try to add, adds these hundrends (maybe thousands) of line of code, altering the columns. As a remedy, I have manually deleted all these lines of code, but I would like to know the root cause and how to solve this issue, as the migrations file has more than 110 thousand lines.
Any help will be GREATLY appreaciated.
Include provider and version information
EF Core version: 8.0.6
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .net 8
Operating system: Windows 10 Pro
IDE: Visual Studio 2022 17.8.5
The text was updated successfully, but these errors were encountered:
i think you are misunderstanding how model snapshot works in ef, as you said you have manually deleted all old migrations from previous version ef core cannot see it, the snapshot name in __EFMigrationsHistory is just the migration Id of previous migrations, so now that it cannot see those migrations (deleted code) it will treat whole model as a new database, now you have few options here to fix this issue:
manually opt-out of migrations for the existing tables (mark it ignored using ModelBuilder.Ignore Method)
let everything run once (whether you manually delete extra data/code you have to run atleast first migration for ef to make an actual snashot of existing database.
iirc i saw somewhere here or some other git issue an incremental migration approach which you can use to divide your initial table migration in smaller code bases.
We currently don't have out-of-box support for squashing migrations. The work is tracked in #2174. This issue is in the Backlog milestone. This means that it is not planned for the next release (EF Core 9.0). We will re-assess the backlog following the this release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you.
However, with proper steps, you can do the squashing manually yourself. The steps are described here.
I have an old application in .Net Core 3.1 and EF Core 3.1. I have succesfully migrated to .net 8 and EF Core 8. The migrations folder was HUGE, so I reset the migrations, deleting all records in the
[__EFMigrationsHistory]
table and deleted the migration folder (the migrations folder is in a separate project.I succesfully ran the initial migration and EF created the class with all existing tables, columns, indexes, etc. As the Database already exists, I manually added the migrations record to the
[__EFMigrationsHistory]
table.I then had to add a new table. When I ran the Add-Migration, the resulting class is HUGE (should have only contained the necesarry code for the new table). It includes code for (i think) every column in the database, such as the following:
Any migration I try to add, adds these hundrends (maybe thousands) of line of code, altering the columns. As a remedy, I have manually deleted all these lines of code, but I would like to know the root cause and how to solve this issue, as the migrations file has more than 110 thousand lines.
Any help will be GREATLY appreaciated.
Include provider and version information
EF Core version: 8.0.6
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .net 8
Operating system: Windows 10 Pro
IDE: Visual Studio 2022 17.8.5
The text was updated successfully, but these errors were encountered: