Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net core code first database migrations

How do we use data migrations in asp.net core? I'v tried looking through the asp.net core documentation but couldn't find anything.

This was the code for asp.net 4:

internal sealed class Configuration : DbMigrationsConfiguration<ApplicationDbContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }

    protected override void Seed(ApplicationDbContext context)
    {
        base.Seed(context);

        //Add stuff to database

        context.SaveChanges();
    }
}

What is the equivalent in asp.net core?

like image 718
Martin Dawson Avatar asked Oct 20 '25 13:10

Martin Dawson


1 Answers

If you're using EF core: https://docs.efproject.net/en/latest/miscellaneous/cli/dotnet.html

If you're using EF 6.x, you may need a community one: https://github.com/mrahhal/Migrator.EF6

like image 101
Takahiro Avatar answered Oct 23 '25 04:10

Takahiro