0

I am working on a Blazor Web App using SQL as my database. My initial database migration works fine.

However, when I make a change to one of the model classes, even a simple change, and try and add a migration using the Package Manager Console, the migration consists of the entire database creation, not just the incremental change made. Ultimately, the database update fails because it's trying to create tables that are already present.

6
  • 1
    Check whether the database created by the initial migration has the __EFMigrationHistory table added, that the table was not deleted by someone. Also check that someone hasn't since reconfigured EF to use an alternate migration history table. (Supported in EF Core) (Set via options in UseSqlServer() specifying MigrationHistoryTable("table_name", "schema") If someone changed that since the initial migration, the original migration history records need to be moved manually to the new table. Commented May 16 at 4:24
  • Thanks, @StevePy I'm the only one on this project. In fact it's on my laptop. Also, the migration script is created before initiating the database update. So the script have the entire code from the initial migration. Commented May 16 at 4:26
  • In the database, is there an __EFMigrationHistory table? You can check the contents of this table, as there should be at least one row for the initial migration. Commented May 16 at 4:44
  • 1
    When you add a migration from the CLI, it creates 3 files - the migration itself, a designer file and a snapshot file. Does the previous migration have all three? Commented May 16 at 5:47
  • @AntonPastukhov there isn't a snapshot. The other two are there. Commented May 16 at 14:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.