Reputation: 13
We have some existing applications where we are retrofitting entity framework as an ORM.
The aim is to use code first (from existing database) with migrations, but we are having problems getting migrations to fit to the existing database scenario:
The goals
Using package-manager it is possible to solve 1 with default migration initializer. Or solve 2 with the ignore-changes switch. But no success having both to work simultaneously.
I have tried:
Any other suggestion?
Thx Kim
Upvotes: 1
Views: 349
Reputation: 1677
You can use the entity framework power tools extensions to reverse engineer you existing database into code first. On a development machine with no database do an
add-migration Initial
and
update-database
and you will have model matching production. Script out the __MigrationHistory table and all of the rows and add them to your production database. Your production database will then be ready for future scripts generated from migrations.
The command
update-database -script -SourceMigration $InitialDatabase
will generate a full script for updating your database to the latest version. It checks for the __MigrationHistory table and goes row by row apply schema changes to make the model match the changes in each migration.
Upvotes: 1