question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to prevent column renames in migrations

See original GitHub issue

When 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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ajcvickerscommented, Dec 9, 2021

Note from triage: this is not currently possible. Hopefully, #15178 will make this unnecessary. If not, we may consider this in a future release.

0reactions
icrocketcommented, Sep 26, 2022

Core makes a best effort to interpret changes and scaffold an appropriate starting point for the migration, but it should always be reviewed and edited when necessary for places where it doesn’t match the schema change desired.

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found