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
Drop custom collation in EF migration rollback #3183
I try to add custom collation calling HasCollation(...) in OnModelCreating method of DbContext. Everething good, EF migration generate sql with CREATE COLLATION ....
But when I try to rollback this migration, there is no corresponding sql statement dropping my collation in generated sql script.
In results an error is occured when I try to apply modified migration next time (debug) - it can not create collation, because that already exists (and migration failed).
Is it necessary to add some extra configuration besides HasCollation to correctly rollback migration?
Using Npgsql.EntityFrameforkCore.PostgreSQL v8.0.4
When I use dotnet ef database update <migration> to roll back to a migration state before the collation was added, I can see the collation being dropped:
DROP COLLATION dummy;
You'll have to provide a clear code sample and/or instructions for reproducing the error.
@roji Thank you for answer!
I updated NuGet package and SDK to 8.0.10 and still have the issue.
In very simple case with only one instruction in DbContext.OnModelCreating (.HasCollation(...)) I have empty Down method of migration.
Please check attached code sample with "broken" migration (try to recreate it). CollationRollbackIssue.zip
@Gendolph OK, I can indeed see this happening, but only if the collation is defined when creating the very first migration; if you add it in a later migration, everything seems to be working well. While that's technically an EF bug, the Down() method of the initial migration isn't very useful, as it's supposed to bring the database back to an empty state (you can basically just drop it instead).
I've opened dotnet/efcore#35016 on the EF side to track fixing this, though given the low value it probably won't get much attention any time soon.
I'll go ahead and close this for now, but please post back if I somehow misunderstood or there's a wider issue.
Activity
roji commentedon Oct 27, 2024
Sorry for not answering this sooner.
I cannot reproduce this... When a migration is generated that adds a collation, I can see a Down() method for dropping that collation:
When I use
dotnet ef database update <migration>to roll back to a migration state before the collation was added, I can see the collation being dropped:You'll have to provide a clear code sample and/or instructions for reproducing the error.
Gendolph commentedon Oct 28, 2024
@roji Thank you for answer!
I updated NuGet package and SDK to 8.0.10 and still have the issue.
In very simple case with only one instruction in DbContext.OnModelCreating (
.HasCollation(...)) I have emptyDownmethod of migration.Please check attached code sample with "broken" migration (try to recreate it).
CollationRollbackIssue.zip
I used CLI cmd
dotnet ef migrations add Initialroji commentedon Oct 29, 2024
@Gendolph OK, I can indeed see this happening, but only if the collation is defined when creating the very first migration; if you add it in a later migration, everything seems to be working well. While that's technically an EF bug, the Down() method of the initial migration isn't very useful, as it's supposed to bring the database back to an empty state (you can basically just drop it instead).
I've opened dotnet/efcore#35016 on the EF side to track fixing this, though given the low value it probably won't get much attention any time soon.
I'll go ahead and close this for now, but please post back if I somehow misunderstood or there's a wider issue.
Fix bug where annotations added by initial migration are not removed …
roji commentedon Feb 1, 2026
Note: this is being fixed as part of #3604.