10 Eylül 2012 Pazartesi

code-first wants to recreate the database although the backing model is not changed

When the database is in use in production, you do not have the chance of losing data anymore.. Even though i did not make any changes in the data model, code first wanted to recreate the database by throwing an error message such as

The model backing the 'mycontext' context has changed since the database was created. Consider using Code First Migrations to update the database.

My problem is pretty much the same : http://stackoverflow.com/questions/10254613/mvc3-and-code-first-migrations
" In short, even if Db-s are the same migration table data might not be - and hash comparison may fail."
And luckily, the solution in the link worked for me..
I examined the migration difference by running the following command in package manager:

Update-Database -Script

.. and solved the problem by finding the  INSERT INTO [__MigrationHistory] ...  statement and executing it on ms sql server..

This workaround part of this answer explains the cause of the error: http://stackoverflow.com/questions/9516341/code-first-dbmigrator-causes-error-when-building-from-different-machines/11398366#11398366
According to the answer, the naming of association tables appears to be of an indeterminate order in EF causing the above error.

Hiç yorum yok:

Yorum Gönder