简体   繁体   English

如何在远程ms sql server上更新数据库(EF Code First)

[英]How to update database on remote ms sql server (EF Code First)

While developing an application I used EF automatic migrations. 在开发应用程序时,我使用了EF自动迁移。 So now when I have deployed my app on VPS, I don't know how to add new tables and fields to my database. 所以现在当我在VPS上部署我的应用程序时,我不知道如何向我的数据库添加新的表和字段。

Can I connect to the remote database directly from my project in VS2012, updating a connection string, and update the database using "update-database" in package manager console? 我是否可以直接从VS2012中的项目连接到远程数据库,更新连接字符串,并使用包管理器控制台中的“update-database”更新数据库? Or do I need to install VS on my VPS and update the database from VPS? 或者我是否需要在我的VPS上安装VS并从VPS更新数据库?

My database is already filled with data, so I can't delete it and create again. 我的数据库已经填满了数据,所以我无法删除它并再次创建。

Yes you can use Visual Studio, follow this tutorial - it should work for VS 2012 too. 是的,你可以使用Visual Studio,按照本教程 - 它也适用于VS 2012。
You can also use Code first Migration to update your model by using this command in package manager console: 您还可以使用Code first Migration在包管理器控制台中使用此命令来更新模型:

Update-Database

and you can specify your connection string name: 并且您可以指定您的连接字符串名称:

Update-Database -ConnectionStringName "MyConnectionString"

This is best explained in the link below. 最好在下面的链接中解释。 Read the "Getting a SQL script" section. 阅读“获取SQL脚本”部分。 That will explain how to generate a script which you can then run on your target database. 这将解释如何生成一个脚本,然后您可以在目标数据库上运行该脚本。

This will be necessary if your database access is IP protected for example. 例如,如果数据库访问受IP保护,则必须执行此操作。

https://msdn.microsoft.com/en-us/data/jj591621.aspx https://msdn.microsoft.com/en-us/data/jj591621.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM