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
{{ message }}
Repository navigation
Migrations: Improve existing database support #2167
This need came up while prototyping the solutions for aspnet/Identity#457. In that particular scenario a few new columns need to be added to the database as part of the upgrade, which may or may not pose an additional challenge.
In general EF Core Migrations cannot predict the current schema of a database regardless of how it was created and whether there are additional model changes in the upgrade. Even if the database was maintained using EF6 Migrations there are functional differences between the stacks that will make the database look different.
Here is a set of ideas we talked about that could be used to address this:
We add a way to point our reverse engineering engine to the existing database to obtain a model snapshot (and possibly an accompanying initial migration).
The user creates a migration based on the current EF Core model and the snapshot obtained in the first step.
The user looks at this migration and decides which adjustments should be made to the model (e.g. column and tables renames in OnModelCreating()) to better match the existing database.
After each adjustment to the model the user can go back and re-scaffold the migration created in step 2, iterating over steps 2 and 3 as many times as necessary until a migration representing the desired diff is obtained (the migration should be empty if the model was made match the database completely).
If there are outstanding changes and the database needs to be upgraded the user can make any necessary manual edits to the migration and apply it.
At this point the database in the model can be considered in sync and the user can proceed using Migrations normally.
As @bricelam mentioned above, the database could have been created using EF6 Migrations in which case we will need to do something with the migrations history table, i.e. we either make the EF Core table compatible with the EF6 one in which case we can simply add a new row or we may have to drop/move the table and existing migration history rows somewhere else.
Also, note that the proposal described in a previous comment should be much easier to implement if the IModel that is the output of the reverse engineering pipeline used the same annotations and other constructs that a regular model produced by code first would use (see #2714).
Decided we will handle this with docs. Because there are so many nuances to how you might want it to work, we don't think we can build a high level feature that just works. We may drive improvements to the building blocks as we write the docs.
Activity
divega commentedon May 12, 2015
This need came up while prototyping the solutions for aspnet/Identity#457. In that particular scenario a few new columns need to be added to the database as part of the upgrade, which may or may not pose an additional challenge.
In general EF Core Migrations cannot predict the current schema of a database regardless of how it was created and whether there are additional model changes in the upgrade. Even if the database was maintained using EF6 Migrations there are functional differences between the stacks that will make the database look different.
Here is a set of ideas we talked about that could be used to address this:
OnModelCreating()) to better match the existing database.As @bricelam mentioned above, the database could have been created using EF6 Migrations in which case we will need to do something with the migrations history table, i.e. we either make the EF Core table compatible with the EF6 one in which case we can simply add a new row or we may have to drop/move the table and existing migration history rows somewhere else.
divega commentedon Jul 24, 2015
Noticed this issue has the pri0 but hasn't been assigned. Assigning to @bricelam since he owns our migrations story.
divega commentedon Jul 24, 2015
Also, note that the proposal described in a previous comment should be much easier to implement if the IModel that is the output of the reverse engineering pipeline used the same annotations and other constructs that a regular model produced by code first would use (see #2714).
rowanmiller commentedon Dec 10, 2015
Decided we will handle this with docs. Because there are so many nuances to how you might want it to work, we don't think we can build a high level feature that just works. We may drive improvements to the building blocks as we write the docs.
dotnet/EntityFramework.Docs#91
[-]Migrations: Existing database support[/-][+]Migrations: Improve existing database support[/+]76 remaining items
PilotBob commentedon Feb 27, 2023
If I could +1000 this I would. Love to see something to support this soon.
Maybe a starting migration parameter or a skip 1st [or list] or something.
Thanks.
:)
ericsampson commentedon Nov 29, 2023
It would be great to have some sort of equivalent functionality as the old
IgnoreChanges, just for simplicity/uxCheers