第二次尝试生成脚本sql脚本没有工作 [英] Second attempt to generate script sql script did not work

查看:149
本文介绍了第二次尝试生成脚本sql脚本没有工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的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 ,右键点击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 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.

解决方案

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.

这篇关于第二次尝试生成脚本sql脚本没有工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆