Search code examples
c#entity-frameworkmigrationdatabase-migration

There are no pending changes for EF migration and still it complains that there are pending changes. How does EF keep track of this?


I have several migration files in my project and since I made manual modifications to my last migration I don't want to re-generate it with the "package manager console". I only need to add 1 column. So Added this manually a previous migration (I can do this since no-one has upgraded yet).

Now, when I start my project, the local database seems to create my new column fine but I do get an exception: "Unable to update database to match the current model because there are pending changes and automatic migration is disabled"

It looks like the only way I can solve this is to generate an extra migration - even though, this migation generates exactly the same line of code that i wrote manually in a previous migration...

I was wondering - how does EF keep track of this and is there a way to bypass it ?

Also another question - is it wrong of me to want to limit the amount of migration files that I have ? I currently feel that in an ideal situation each Release of my software should only have 1 migration file at most in order to keep a better overview of my code...

thank you,


Solution

  • EF saves a hash of your serialized Model in the _MigrationHistory table, and compares them when you use migrations to ensure the database schema matches the model. I do not advise trying to bypass this. If you wish to mimimise the number of files then you can rollback then combine the migrations. But I don't think it's worth it. I just put my migrations into sub-folders periodically

    I recommend this article:

    http://elegantcode.com/2012/04/12/entity-framework-migrations-tips/