简体   繁体   中英

EF Migration from Localhost to Production

I am working on ac# web application. currently i am testing on my local host as in 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?

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.

now on production, after i have published to my www root on production, will this changes happen automatically?

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.

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. So you should not lose your content's integrity. Though you may execute custom sql inside your migrations if needed. Sql() is the function for that.

Bottom line, if you do not use DropCreateDatabaseIfModelChanges or DropCreateDatabaseAlways in the production code you are relatively safe.

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.

This link for a list of EF commands that can be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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