-
Notifications
You must be signed in to change notification settings - Fork 156
Migrations
Bryce-L edited this page Nov 23, 2013
·
3 revisions
The combination of EF code first, azure, and the simple membership provider means that the EF automatic migrations don't work. The automatic migrations want to remove the tables, but the model table has a link to the membership provider link. Those fail.
Instead, we follow the manual migrations strategy for our model. We pretty much follow what's there, with the following differences:
- Make sure to use the package manager console to apply the migrations locally.
- Use the update-Migrations command to generate a script that runs against the Azure DB.
- Create an initial database with no tables.
- Open the package manager console, choose the Models project from the dropdown list and type
Update-Database
.
- Open the package manager console, choose the Models project and type
Update-Database
.
- Confirm that there are no migrations pending. Open the package manager console, choose the Models project and type
Update-Database
. - Make the changes to the model and context for the database.
- In the package manager console, add a new migration to the Models project.
PS> Add-Migration [MigrationName]
- Make any necessary customizations to the migration script.
- Open the package manager console, choose the Models project, and update the database (this will open a SQL script in a new window).
PS> Update-Database -Script -SourceMigration [Source Migration Name] -TargetMigration [New Migration Name]
- Save the SQL script to the project in the
MigrationScripts
folder and commit your changes.
NOTE: A system table is created that tracks the migrations. If a migration is run once, it will update the migration system table so that it can't be run again.