How could I change the name of an old migration (rename it)? It conflicts with the name of my custom identity user.
Would changing the identity user be easier? I have no idea how to rename that either, every tutorial out there just create a new db for the sake of simplicity (any information about that is appreciated too).
Is it as simple as renaming it in:
Is that it? Any idea if this could screw things up?
Migration in Entity Framework Core Migration is a way to keep the database schema in sync with the EF Core model by preserving data. As per the above figure, EF Core API builds the EF Core model from the domain (entity) classes and EF Core migrations will create or update the database schema based on the EF Core model.
If you want to use this method for EF Core, definitely do the two steps with two separate migrations: ColumnChanged_A, then ColumnChanged_B. If you don't you risk having your DBModelSnapshot reference the old Property name. (maybe this will always sort itself in later migrations, but still seems kinda risky)
For example, if you rename a property from Name to FullName, EF Core will generate the following migration: EF Core is generally unable to know when the intention is to drop a column and create a new one (two separate changes), and when a column should be renamed. If the above migration is applied as-is, all your customer names will be lost.
Sometimes you add a migration and realize you need to make additional changes to your EF Core model before applying it. To remove the last migration, use this command. Remove-Migration dotnet ef migrations remove. After removing the migration, you can make the additional model changes and add it again.
If it's just the class name conflicting, only renaming the class should be sufficient.
If you really want to rename the whole migration, your steps look correct. Make sure you check the *.Designer.cs
file to rename the string literal containing the name.
As far as a direct answer to the actual question since I got here by googling:
It's not a simple as just renaming the migration file. Especially if the migration has already gone out to client databases.
I've found that EF still remembers the name of the old migration somewhere and ends up still inserting the old name in the __EFMigrationsHistory
table even after renaming the migration file, designer file, and class name.
For me it was easier to copy all the code in the Up and Down methods to a notepad, use remove-migration
to delete the wrongly named migration, then use add-migration
to add a new one with the desired name and copy back in all the code from the notepad I saved. However, that ONLY works if the migration is the latest one.
If it's an older one, already out to client dbs, or superseded by other migrations, you'll have to worry about updating the __EFMigrationsHistory
table manually somehow and EF's memory of the migration name wherever that is, which could get pretty tricky.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With