Search code examples
c#sql-serverasp.net-mvcentity-frameworkdatabase-migration

EF Migration from Localhost to Production


I am working on a c# 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


Solution

  • 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.