dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.67k stars 3.16k forks source link

custom migration name and support for undo #34748

Closed herme063 closed 3 hours ago

herme063 commented 4 hours ago

I have implemented a process where I renamed the migration name to something custom. I needed to do this because my code base runs in both net6.0(dev) and net2.1(qa). I was having issue when deploy dev code to qa database because the migration generated would have different names but the changes are already in the db. So instead of the timestamp prefix, I am using the template [IssueNumber]_[HumanFriendlyName]. This allow me to keep the migration name consistent between branches avoiding migration issue.

However, I found out that undoing migration no longer works as expected. The new migration names are still in alphabetical order, so I don't understand why it does not work: The migration '123456_AddColumnA' was not found. The migration in question is in the migration history table.

How do we make this work?

herme063 commented 3 hours ago

After searching through the code, I changed the new name template so that the prefix matches the timestamp format (14 digits). This seems to work for now. I would still like to know if there is a better way to handle custom migration name.

roji commented 1 hour ago

/cc @maumar