EF Core migration fails with "There is already an object named Users". How do I fix it?
EF Core migration fails because the Users table already exists
This means EF is trying to run a CreateTable("Users") operation, but that table is already in the database. Do not delete the table in a database that contains data just to make the migration pass.
First check whether the database has EF Core migration history:
SELECT * FROM __EFMigrationsHistory;If the table was created outside the current migration history, create a baseline instead of applying an initial migration that creates all existing tables. Remove or replace the pending initial migration, then add a migration that represents the current schema without creating it. Future migrations should contain only schema changes.
For a disposable development database, the simple fix is usually to delete the database, then run:
dotnet ef database updateAlso verify you are targeting the database and connection string you expect. This error commonly happens when a migration is run against an older database, or when multiple applications or contexts use the same database but do not share migration history.
- If a previous migration failed halfway through, inspect the actual schema and
__EFMigrationsHistorybefore retrying. - Do not manually insert migration-history rows unless the database schema has been verified to exactly match that migration.
- After baselining, use
dotnet ef migrations add <name>for the next real model change, then apply it withdotnet ef database update.

Answers
Know the answer? Post it. Somebody with the same question will find it here.