EF Data migrations won't detect changes when adding new migration

后端 未结 16 1853
情话喂你
情话喂你 2020-12-09 14:53

I am using Entity Framework 5.0 Data migrations along with code first. When i add a new field to my model and execute the following command in the package manager console.

相关标签:
16条回答
  • 2020-12-09 15:22

    Just got the same problem but figured out that my new field was added as a member variable and not a property - it was missing the {get; set;} part and that makes migration skip that field.

    May not be your case but it might help someone else.

    0 讨论(0)
  • 2020-12-09 15:22

    If you are using fluent api to set up your configurations for the DbSets then you won't have any problems with it

    0 讨论(0)
  • 2020-12-09 15:23

    I had a problem similar to this, where using the -force flag on add-migration to re-scaffold an existing migration stopped working for no apparent reason.

    No matter what I did I got the stupid "Unable to generate an explicit migration because the following explicit migrations are pending" error message. After trying nearly everything I could think of and stopping just short of smashing my laptop to pieces, out of desperation I ran enable-migrations again and of course got the "Migrations have already been enabled in project 'Blah.Blah'" message. Tried add-migration -force again and magically it was working.

    I have no idea what it changed- must have been some user settings/config file outside of source control. Hopefully this will help someone else.

    0 讨论(0)
  • 2020-12-09 15:26

    It seems that i managed to solve the problem by moving the models and the context class to another project.

    I still have no idea why this happened, and this solution is really no solution at all :(

    0 讨论(0)
提交回复
热议问题