第二次尝试生成脚本sql脚本没有工作 [英] Second attempt to generate script sql script did not work
问题描述
我正在开发的ASP.NET MVC 5和Entity Framework以code-第一种方法的应用程序。
首先,我在我的数据上下文文件中的一个阶级和一切工作。 启用的迁移
,添加迁移
和更新数据库
被工作正常,但第二次,我增加了更多的类,并试图执行这些语句:
启用的迁移-ContextTypeName IdentityDb -MigrationsDirectory DAL \\ IdentityMigrations启用的迁移-ContextTypeName SMSContext -MigrationsDirectory DAL \\ SMSMigrations添加迁移-ConfigurationTypeName SMSApp.DAL.IdentityMigrations.ConfigurationInitialCreate
我得到一个异常:
称为InitialCreate'A previous迁移已应用到目标数据库。如果你的意思是重新脚手架'InitialCreate,通过运行更新,数据库-TargetMigration $ InitialDatabase恢复它,然后删除201409261933262_InitialCreate1.cs并运行添加 - 迁移InitialCreate'试。
块引用>解决方案在Solution Explorer中点击图标显示所有文件。不是去
的App_Data code>,右键点击MDF文件并打开。
在服务器资源管理器中单击您的连接上的连接,然后右键单击然后将其关闭,然后再次右键单击然后将其删除,然后删除从Solution Explorer中的mdf文件(这将它移动到回收站,就不会丢失但如果你决定把它找回来)。然后在电源外壳包控制台
更新数据库
。注意:这将完全从
配置/ Migrations.cs重建数据库插入记录
种子
方法,你会丢失的其他数据。还可以找到AutomaticMigrations
在code和将其设置为真正
。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
andupdate-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.
解决方案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 findAutomaticMigrations
in the code and set it totrue
.这篇关于第二次尝试生成脚本sql脚本没有工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!