Enabling Migrations
Run the Enable-Migrations command in Package Manager ConsoleGenerating & Running Migrations
Add-Migration migration_nameUpdate-Database –Verbose
Update-Database –TargetMigration: migration_name
If you want to roll all the way back to an empty database then you can use
Update-Database –TargetMigration: $InitialDatabase
Getting a SQL Script
Update-Database -Script -SourceMigration: $InitialDatabase -TargetMigration: migration_nameAutomatically Upgrading on Application Startup (MigrateDatabaseToLatestVersion Initializer)
When we create an instance of this initializer we need to specify the context type (MyDbContext) and the migrations configuration (Configuration) - the migrations configuration is the class that got added to our Migrations folder when we enabled Migrations.Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyDbContext, Configuration>());
References:
http://msdn.microsoft.com/en-us/data/jj591621.aspx
No comments:
Post a Comment