ccoutinho
ccoutinho

Reputation: 4534

Add migration issue with a nonexistent table

When I generate a migration, it fails to reckon that I don't have a certain table (Reports) in the DB, so the generated migration is empty. Nonetheless, I have all the code in place for the generation to run smoothly.

This code is old and was left unfinished until today. Moreover, I can't find any migration referring to the aforementioned table, but for some reason, it thinks the table already exists in the DB. For example, if I change the table name in the Mapping class, like shown below, it will generate a migration with a RenameTable command. And of course, the update-database command will fail.

this.ToTable("Report");

Any idea on how I can solve this?

Upvotes: 0

Views: 1384

Answers (1)

ccoutinho
ccoutinho

Reputation: 4534

As pointed out in the comments, the problem was fixed by using the following hack:

  1. Remove the Entity, and comment out all the locations where it was being used.
  2. Create a migration and clear the code from Up and Down methods.
  3. Apply the migration.
  4. Re-Add the Entity.
  5. Create another migration. It should now generate code to add the table.

Upvotes: 2

Related Questions