-
Where is stored information about current database state (what migration is applied)? I suppose it can be “dbo.__MigrationHistory” table or this table is just for logging purpose?
-
If I enabled migration, added migration and updated my database. After that I checked-in code to SVN and another developer checked it out. What this another developer has to do to create/update his own database?
I see such options:
1) Call Update-Database command right away.
2) Do everything from beginning (Enable-Migration, Add-Migration, Update-Database).
3) Do everything but skip Add-Migration step (it is already present and it seems strange to add it once again for every new developer).
Which of my assumption is right or if no one where is the right way?
To retrieve which migrations have been applied to the database, you can use the
Get-Migrationscommand (reference).Everything depends on how the database is created, which initializer you are using.
This article is worth reading if you are unfamiliar with those.
When using the
DropCreateDatabaseAlwaysinitializer, you don’t really need to care about updating your database, because your database will be deleted & recreated at each application startup.When using the
DropCreateDatabaseWhenModelChangesinitiliazer, your database will be dropped then recreated if EF detects the model has changed at the application startup.When using the
CreateDatabaseIfNotExistsinitilizer or if no initializer has been defined, your database will be created if it does not already exists. If the database already exists & you added a Migration, you (and every developer retrieving your code) need to use theUpdate-Databasecommand to update the database.There is a new initializer introduced with Code-First Migrations:
MigrateDatabaseToLatestVersion, this initializer automatically update the database to the latest Migration defined.See this page’s last section: http://msdn.microsoft.com/en-us/data/jj591621.