Entity Framework Enable Migrations


To enable Code First Migrations in entity framework, use the command


on the Package Manager Console.

You need to have a valid DbContext implementation containing your database objects managed by EF. In this example the database context will contain to objects BlogPost and Author:

internal class DatabaseContext: DbContext
    public DbSet<Author> Authors { get; set; }

    public DbSet<BlogPost> BlogPosts { get; set; }

After executing the command, the following output should appear:

PM> Enable-Migrations
Checking if the context targets an existing database...
Code First Migrations enabled for project <YourProjectName>.

In addition, a new folder Migrations should appear with a single file Configuration.cs inside: DB Project layout

The next step would be to create your first database migration script which will create the initial database (see next example).