0

We use EF 6 with code first migrations in our MVC-Project by generating all the migration files in a dedicated C# project. After forward integrating from development into a feature branch, we suddenly have the situation that when creating a new migration – using the add-migration command in package manager – we get a lot of changes, although the __MigrationHistory Table in the database is up-to-date and we did not made new changes in the model. What went wrong? Where the scaffolding does really check for changes? Any idea how to find why EF is generating changes that we already have in earlier migration files?

Updated: The ConnectionString configuration is right (as usual). I tried the following: copied the production database and updated the production database with the latest migrations. After running update-database I get the message: “The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration Test_homogeo' again.” So I now run again Add-Migration and I get a migration file containing tables that I already have in the database and in the latest 4 migration files. Somehow I think that the last migrations did not work, but I have them in the __MigrationHistory and in the database schema. I have no idea what to try next in order to find the problem. Any thoughts?

  • Possible duplicate of [Why does Add-Migration sometimes create duplicate migrations?](http://stackoverflow.com/questions/19136066/why-does-add-migration-sometimes-create-duplicate-migrations) – Lukas Kabrt Oct 20 '15 at 19:29

2 Answers2

1

I didn’t found the problem, but I found a workaround. Perhaps someone else will have the same problem. Delete all code from the Up() and Down() methods of the last “unwanted”/”already existing” migration. Update the database with Update-Database. When adding again a new migration with Add-Migration the “unwanted”/”already existing” changes will not be detected anymore. As an alternative solution try to use the flag –IgnoreChanges with the command Add-Migration.

-1

It checks the DB schema, Your migrations folder and the _MigrationHistory Table. You must have missed something somewhere. Try checking your connection strings.

azuneca
  • 1,053
  • 13
  • 15