Is it possible to prevent column renames in migrations
See original GitHub issueWhen I delete a property and introduce another one with a similar name EF often creates a migrationBuilder.RenameColumn
in the migration. But usually that’s not what I want and then I have to work around that by either splitting it up in two migrations or manually altering the created migration.
Is there a feature that I don’t know to tell maybe the Add-Migration
command to not do column renames?
Or do you have other best practices?
BR Matthias
EFCore 5.0.7, .Net 5.0, MSSQL
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Change or rename a column name without losing data with ...
It that case create a new column set the new column = to the old column then drop the old column.
Read more >Ef core - renaming of a column but keep existing data and ...
You can generate a new migration with the renamed property (column) and then adjust the generated migration file to rename instead of drop....
Read more >Avoiding downtime in migrations
Renaming columns the standard way requires downtime as an application may continue to use the old column names during or after a database...
Read more >Dangerous migrations in Rails and how to handle them
It's identical to the rename column solution. Create a new column, write data into both of them, then switch to the new column...
Read more >Managing Migrations - EF Core
While renaming a column can be achieved via a built-in API, in many cases that is not possible. For example, we may want...
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
Note from triage: this is not currently possible. Hopefully, #15178 will make this unnecessary. If not, we may consider this in a future release.
Sure @ajcvickers, but we have a slightly different context: we create migrations starting from dynamic types compiled at runtime (Roslyn) and added to the DbContext models. In our case, the migrations are very simple (adding / removing fields) but we still encountered the “rename column” problem.
Therefore, in our single case, it would have been great to have a complete removal of that behavior as well.
As far as we are concerned, it will be enough for us to carry out atomic migrations (field by field). We will await your future feedback on improving the efcore migrations heuristics.
Thank you!