简体   繁体   English

EF从Localhost迁移到生产

[英]EF Migration from Localhost to Production

I am working on ac# web application. 我正在研究ac#web应用程序。 currently i am testing on my local host as in visual studio mvc c# local host. 目前我正在我的本地主机上测试,如在visual studio mvc c#local host中。 I have done several additions and created new tables; 我做了几个补充并创建了新表; I used migration. 我用过迁移。 each time i enable-migration, then add-migration, then update database. 每次启用迁移,然后添加迁移,然后更新数据库。 now here is my question. 现在这是我的问题。 all of this migration happened on my local host, now on production, after i have published to my www root on production, will this changes happen automatically, will i lost the production database content when i copy over from local host to production? 所有这些迁移都发生在我的本地主机上,现在正在生产中,在我发布到生产的www root后,这种更改是否会自动发生,当我从本地主机复制到生产时,我是否会丢失生产数据库内容?

basically all i want is the new table fields and structure NOT content to be published or copied over to production. 基本上我想要的只是新的表字段和结构不是要发布或复制到生产的内容。

thanks 谢谢

Assuming you are using EntityFramework. 假设您正在使用EntityFramework。

now on production, after i have published to my www root on production, will this changes happen automatically? 现在正在制作中,在我发布到生产的www root后,这种变化会自动发生吗?

This actually depends on your configuration. 这实际上取决于您的配置。 By default it does not unless you told it to. 默认情况下,除非你告诉它,否则它不会。 If you want to automatically upgrade the database applying any pending migrations register MigrateDatabaseToLatestVersion database initializer. 如果要自动升级数据库,则应用任何挂起的迁移注册MigrateDatabaseToLatestVersion数据库初始化程序。

will i lost the production database content when i copy over from local host to production? 当我从本地主机复制到生产时,我会丢失生产数据库内容吗?

By the word content if you mean data and by copy over if you mean applying the migration then EF does not have a native data motion support yet. 如果您指的是数据 ,则通过单词content,如果您的意思是应用迁移,则通过复制,则EF还没有本机数据运动支持。 So you should not lose your content's integrity. 因此,您不应该失去内容的完整性。 Though you may execute custom sql inside your migrations if needed. 虽然您可以根据需要在迁移中执行自定义sql。 Sql() is the function for that. Sql()就是这个功能。

Bottom line, if you do not use DropCreateDatabaseIfModelChanges or DropCreateDatabaseAlways in the production code you are relatively safe. 最重要的是,如果您不在生产代码中使用DropCreateDatabaseIfModelChangesDropCreateDatabaseAlways ,则相对安全。

As far as I know, the data don't change if you don't specify it, but you should try to create a staging environment with a copy or restore of production database to test the migration success. 据我所知,如果您没有指定数据,数据不会更改,但您应该尝试创建一个带有生产数据库副本或还原的暂存环境,以测试迁移成功。

Anyway, depending on the migration mode you are using, the production database will be affected. 无论如何,根据您使用的迁移模式,生产数据库将受到影响。 Take a look at this MSDN link for further info. 请查看此MSDN链接以获取更多信息。

This link for a list of EF commands that can be helpful. 链接提供了有用的EF命令列表。

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

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