I'm using Entity Framework 5 in a project, and I've got Migrations enabled.
Here's the scenario:
A new developer (dev1) comes on and builds the project from source. There are existing migrations since previous developers had been working on the project in the past.
When that developer runs the ASP.NET MVC project for the first time, the database builds automatically, and no errors appear.
After that, however, a different developer (dev2) adds a new migration. When Dev1 tries to run Update-Database
, all of the previous migrations are attempted to run. But they have already been applied, since they were part of the initial model as Dev1 saw it. This often results in a schema error since it's trying to apply a schema change that already exists.
So, optimally, it would be great to just "fast forward" the local database to the current migration. But I don't know of a way to do that. Alternatively, is there some other way to initialize the database so that I can apply all the migrations during initialization?
I figured out a hack.
Run Update-Database -Script
Pick out all the migrations that have already been run
INSERT INTO [__MigrationHistory] ([MigrationId], [Model], [ProductVersion]) VALUES
Open Sql Server Management Studio, and run those sql statements manually.
New migrations should work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With