Why I can't get Entity Framework Migration to initial state?

故事扮演 提交于 2019-12-05 04:43:02

问题


I have deleted development database, and Migrations folder from project. When running unit test with use my project development database is recreated. I don't understand why running update-database gives me

PM> Update-Database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying code-based migrations: [201302201840012_wieleDoWielu].
Applying code-based migration: 201302201840012_wieleDoWielu.

Why migration: 201302201840012_wieleDoWielu is remembered ? How Can I delete it? Where is stored?

Best Regards Przemysław Staniszewski


回答1:


Here's a answer. Please recover migration folder and its migrations file (recover to your project). Then follow steps from my theard http://pawel.sawicz.eu/entity-framework-reseting-migrations/

1) Update-Database -Targetmigration:0 - it's the key! first
2) Wipe out tables/migrations (you dont have to delete whole folder)
3) Add-Migration Initialise
4) Update-Database




回答2:


Try these commands Sqllocaldb.exe stop V11.0 Sqllocaldb.exe delete V11.0

This should remove the reference. You may have to comment out some of the changes before doing this and then re-instating the changes back into model before doing the migration.

I'm new at this, so hopefully I am understanding your problem, because it sounds like the same one I encountered recently.

A more permanent solution may be to add the following code to your Globel file and replace the with what you need it to be. The article for this can be found at the link below also:

Database.SetInitializer(new DropCreateDatabaseIfModelChanges<PersonContext>()); 

http://ilmatte.wordpress.com/2012/12/05/entity-framework-5-code-first-enabling-migrations-in-a-real-project/



来源:https://stackoverflow.com/questions/15025622/why-i-cant-get-entity-framework-migration-to-initial-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!