Entity framework code first - how to run Update-Database for production database

asp.net-mvc c# entity-framework

Question

I wanting to know how to run the 'Update-Database' command for a production database.

The 'Update-Database' database works fine from my local machine, but how do I get this to work for production data?

So, if I make a change to my application and then run the 'publish' through visual studio this works fine for the code side of things, but how do I run the 'Update-Database' command for the production data.

Hope this question makes sense...

Thanks,

1
72
3/30/2013 5:23:35 AM

Accepted Answer

To add on what @David said already...

Personally, I don't trust automatic updates in 'live' scenarios, and I always prefer manual database administration (i.e. there is a problem with permissions needed to create or alter Db - not to mention shared hosting etc.) - but from what I've seen migrations are pretty solid when it comes to synchronizing (in fact, the only way to 'untie' them normally is to remove the Db and force full/fresh update).

Here is a post I made a while ago on how to script and synchronize database / code and geared towards deployment scenarios (and when problems arise). It doesn't apply to you (yet) but something to keep in mind.

MVC3 and Code First Migrations - "model backing the 'blah' context has changed since the database was created"

24
5/23/2017 12:18:20 PM

Popular Answer

See Using Entity Framework (code first) migrations in production so that your application automatically updates the database when the Entity Framework initializes.

Now if you're more comfortable having manual control over the migration, you could use the -Script argument to the Update-Database command on your developer machine to generate SQL scripts which you can then run against the production database.

http://msdn.microsoft.com/en-us/data/jj591621.aspx (see Getting A SQL Script section)



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow