0

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

galdin
  • 12,411
  • 7
  • 56
  • 71
NULL
  • 1,559
  • 5
  • 34
  • 60
  • Poss [duplicate](http://stackoverflow.com/questions/1126571/import-export-database-with-sql-server-server-management-studio) or [this](http://stackoverflow.com/questions/3589/backup-sql-schema-only) – OneFineDay Aug 18 '13 at 02:44
  • DonA actually it is not a duplicate. I am working in C# MVC and it says to do migration when I am publishing, the links you posted has nothing to do with migration. thanks anyways. – NULL Aug 18 '13 at 03:42
  • I was thinking that it solves the issue, but your needs are more specific. – OneFineDay Aug 18 '13 at 03:44

2 Answers2

2

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.

Shuhel Ahmed
  • 963
  • 8
  • 14
0

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.

Daniele
  • 1,938
  • 16
  • 24