0

Almost every time I try to update my database with Entity Framework Code-First Migrations, I get the error saying that I need to apply the previous Migration to the database.

So I run the update-database command and this complains that:

There is already an object named ... in the database.

In every case, the object that its complaining about is a table which is literally supposed to be there.

This answer doesn't help since the root problem is the fact that I can't add a migration.

Only way I know to fix this is to physically delete the database from SQL Server and let EF recreate it but that's not always a practical course for obvious reasons.

How do I get around this problem so that I can add the migration?

Ortund
  • 8,095
  • 18
  • 71
  • 139
  • Manual or automatic migrations? – grek40 Feb 06 '18 at 08:12
  • Manual migrations. Automatic migrations are always disabled by default and I don't ever look at that part of the code – Ortund Feb 06 '18 at 08:15
  • 1
    Have a look at your generated migrations... are there two distinct migrations that try to generate the same object? If so, how/why did the object appear in the first migration? Was it auto-scaffolded or manually added to the migration? Since you say *"table which is literally supposed to be there"*, it's important to know whether the EF model should know about this literal existence or if it is just there in the real DB model... – grek40 Feb 06 '18 at 08:25

0 Answers0