May be this question seems duplicate. But here are the issue that I am facing with the command.
也许这个问题是重复的。但这是我在指挥中心面临的问题。
If I run this command,
如果我运行这个命令,
update-database -force
the first error I gets..
我得到的第一个错误。
There is already an object named tblAbc in the database
数据库中已经有一个名为tblAbc的对象
Then I googled and everytime I get a stackoverflow link for suggesting to run Add-Migration Initial -IgnoreChanges
然后我在谷歌上搜索,每次我得到一个stackoverflow链接,建议运行初始的-IgnoreChanges
If I run this command and then run the update command, No error - Running seed method
如果我运行这个命令,然后运行更新命令,没有错误运行种子方法
But it doesn't sync the database with the new updates
但它不会将数据库与新的更新同步
Then I tried for number of times but same issue, hence I looked for some alternate solution & I got.
然后我试了很多次,但都是一样的问题,所以我找了其他的解决办法。
to use update-database -Script but if I run this command and get the following error.
要使用update-database -Script,但是如果我运行此命令并得到以下错误。
User canceld Save dialog box
用户取消保存对话框
Then I tried to fix this by opening SQL Managment Studio and
然后我尝试通过打开SQL Managment Studio来解决这个问题。
Tools>>Options>>designers>> unchecked the Prevent saving changes that required table recreation
工具>>选项>>设计者>>未检查防止需要重新创建表的保存更改
But after this also same error message.
但在此之后,同样的错误信息。
Then I tried to add the following coniguration in my context class
然后,我尝试在我的上下文类中添加下面的代码。
System.Data.Entity.Database.SetInitializer(new MigrateDatabaseToLatestVersion <context, Configuration>());
It ran with success and Running Seed method but it doesn't sync the latest updates.
它运行成功并运行Seed方法,但不同步最新的更新。
4
Using an Existing Database
使用一个现有的数据库
Depending on the state of your context you need to the one of the following...
取决于你的上下文的状态,你需要以下其中一个……
IF YOUR DATABASE CONTEXT CONTAINS ONLY YOUR EXISTING TABLES AND NO CUSTOM CHANGES DO THE FOLLOWING
如果您的数据库上下文只包含现有的表,并且没有自定义更改,则执行以下操作
Add-Migration Initial -IgnoreChanges
This will create a blank migration script
这将创建一个空白迁移脚本。
update-database
This will update the database to this migration but no changes will be applied. You can now add your changes to the database context. After you have finished do the following
这将把数据库更新到此迁移,但不会应用任何更改。现在可以将更改添加到数据库上下文。在你完成以下工作之后。
Add-Migration Custom
This will generate a migration script with your changes in it. Then update your database again.
这将生成一个带有您的更改的迁移脚本。然后再次更新数据库。
update-database
IF YOUR DATABASE CONTEXT CONTAINS YOUR EXISTING TABLES AND ALSO YOUR CUSTOM CHANGES
如果数据库上下文包含已有的表和自定义更改
Add-migration Initial
This generates a migration script. Go through the migration script and remove any references to existing tables in both the UP and DOWN methods. You will be left with a script which only includes your custom logic.
这将生成迁移脚本。遍历迁移脚本,并在UP和DOWN方法中删除对现有表的任何引用。剩下的脚本只包含自定义逻辑。
update-database
Hope this helps!
希望这可以帮助!
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2015/11/04/3a45ad35a23db6e08323df8e4eea922a.html。