The model backing the 'DataContext' context has changed since the database was created

后端 未结 4 548
迷失自我
迷失自我 2021-01-17 14:29

I am trying to use Code First with Migrations. Even though there are no current changes to my model, I\'m getting an exception. When I add a migration, the up and down are e

相关标签:
4条回答
  • 2021-01-17 15:08

    I am not sure if you found the answer to your problem, but this other answer I found here actually did it for me: Entity Framework model change error

    I actually ended up deleting the __MigrationHistory table in SQL Server which I didn't know it was being created automatically.

    The article also talks about the option to not generate it I think by using this instruction: Database.SetInitializer<MyDbContext>(null); but I have not used it, so I am not sure if it works like that

    0 讨论(0)
  • 2021-01-17 15:19

    I bet your data context is not hooking up the connection string. Check if it's not initialized with a localdb (something like (localdb)\v11.0) and not working with that when you might think it's set to something else.

    0 讨论(0)
  • 2021-01-17 15:22

    My issue ended up being a conflict between Automatic Migrations being enabled and the initializer MigrateDatabaseToLatestVersion as described here.

    0 讨论(0)
  • 2021-01-17 15:29

    This worked for me.

    Go to Package Manager Console and Run - Update-Database -force

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