I can use package manager to run \'update-database -verbose\' locally.
Probably a stupid question but I can\'t find it online - once my website is deployed - how can I r
A simple solution: running Update-Database
from your local Package Manager Console providing a connection string parameter with the production connection string. You also have to provide the connection provider name (SqlServer in this example code):
Update-Database -ConnectionString <your real remote server connection string here> -ConnectionProviderName System.Data.SqlClient
Instead of the connection string you can use a connection string name present in your app.config file connectionStrings
section:
Update-Database -ConnectionStringName <your connection string name here>
You must have permissions to access that server from your local machine. For example, if you are able to connect to the server from a Sql Server Management Studio you can use this.
Note that this approach is not recommended for a real production system, you should use something like what is explained in the accepted answer. But it can help you with quick hacks in development remote servers, test environments, etc.
just to give everyone the simple answer.
This is the "Update-Database" In your Migrations folder, Configuration.cs:
internal sealed class Configuration : DbMigrationsConfiguration<projectname.Models.dbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true; // Update-Data -Force (deletes columns etc)
}
And to "Enable migrations" in the first place on a remote server, add this to your Global.asax.cs file:
protected void Application_Start()
{
....
System.Data.Entity.Database.SetInitializer(new MigrateDatabaseToLatestVersion<dbContext, Migrations.Configuration>());
For us, the DBAs are the only group to have access to the production (and pre-production) environments. We simply use the Update-Database -Script
package console command to get the Sql required to update the database. This gets handed off to them where they can validate it, etc.
Maybe a little too simplistic for some but it works.
HTH.
I personally like to setup automatic migrations that run every time the application's start method is called. That way with every deployment you make you have the migrations just run and update the application automatically.
Check out this post from AppHarbor. http://blog.appharbor.com/2012/04/24/automatic-migrations-with-entity-framework-4-3
The gist is basically you want to enable auto migrations then call the DatabaseInitializer from your code, either from the OnModelCreating method or from your Global.asax.
I know that the question is already answered, but for future reference:
One of the options is to put something like this in the constructor of your DB context class:
public MyDbContext()
{
System.Data.Entity.Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyDbContext, Configuration>());
}
You have a couple of options:
update-database -script
to generate the SQL commands to update the database on the server/packages/EntityFramework5.0.0/tools/migrate.exe
. I've used it successfully in the past with Jet Brains' Team City Build Server to setup the migrations with my deploy scripts.Update: Also, check out Sayed Ibrahim's blog, he works on the MsBuild Team at Microsoft and has some great insights on deployments