I have added EF 5 to my project via Nuget and enabled migrations with the \"Enable-Migrations\" command. I have then called \"Add-Migration\" to generate the base code for g
I had the same problem enabling EF migrations for a code-first model with an existing database, and the following procedure worked:
__MigrationHistory
from the existing database.enable-migrations
command from the Package Manager Console.add-migration
command to create an initial migration.Up()
method for the initial migration.update-database
command to apply the initial migration to your database.
This doesn't make any changes to existing objects (because the Up()
method contains no code), but it marks the existing database as having been migrated to the initial state.add-migration
command to create a new migration.
The code in the Up()
method of the new migration will contain only the changes to your object model.update-database
command to apply the changes to your database.