Second attempt to generate script sql script did not work

感情迁移 提交于 2019-12-11 10:46:56

问题


I am developing an application in ASP.NET MVC 5 and Entity Framework with a code-first approach.

Firstly, I had one class in my data context file and everything worked. enable-migrations, add-migration and update-database were working fine but second time, I added more classes and tried to execute these statements:

enable-migrations -ContextTypeName IdentityDb -MigrationsDirectory DAL\IdentityMigrations

enable-migrations -ContextTypeName SMSContext -MigrationsDirectory DAL\SMSMigrations

add-migration -ConfigurationTypeName SMSApp.DAL.IdentityMigrations.Configuration "InitialCreate"

I get an exception:

A previous migration called 'InitialCreate' was already applied to the target database. If you meant to re-scaffold 'InitialCreate', revert it by running 'Update-Database -TargetMigration $InitialDatabase', then delete '201409261933262_InitialCreate1.cs' and run 'Add-Migration InitialCreate' again.


回答1:


In Solution Explorer click icon Show All Files. Than go to App_Data, right click on mdf file and open.

In Server Explorer click on connections and right click on your connection then close it, then right click again then delete it, then delete the mdf file from the Solution explorer(this will move it to the trash bin, it is not lost yet if you decide to get it back). Then in power shell package console update-database.

NOTICE: This will totally rebuild your database inserting records from Configuration/Migrations.cs Seed method, you will lose other data. Also find AutomaticMigrations in the code and set it to true.



来源:https://stackoverflow.com/questions/26074330/second-attempt-to-generate-script-sql-script-did-not-work

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