How to add migration in asp.net core 1.0

I had a problem creating a migration, the migration was not created when I created the migration in a package in

DbInitializer

public static class DbInitializer
{
    public static void Initialize(SchoolContext context)
    {
        context.Database.EnsureCreated();

        // Look for any students.
        if (context.Students.Any())
        {
            return;   // DB has been seeded
        }

        var students = new Student[]
        {
        new Student{FirstMidName="Carson",LastName="Alexander",EnrollmentDate=DateTime.Parse("2005-09-01")},
        new Student{FirstMidName="Meredith",LastName="Alonso",EnrollmentDate=DateTime.Parse("2002-09-01")},
        new Student{FirstMidName="Arturo",LastName="Anand",EnrollmentDate=DateTime.Parse("2003-09-01")},
        new Student{FirstMidName="Gytis",LastName="Barzdukas",EnrollmentDate=DateTime.Parse("2002-09-01")},
        new Student{FirstMidName="Yan",LastName="Li",EnrollmentDate=DateTime.Parse("2002-09-01")},
        new Student{FirstMidName="Peggy",LastName="Justice",EnrollmentDate=DateTime.Parse("2001-09-01")},
        new Student{FirstMidName="Laura",LastName="Norman",EnrollmentDate=DateTime.Parse("2003-09-01")},
        new Student{FirstMidName="Nino",LastName="Olivetto",EnrollmentDate=DateTime.Parse("2005-09-01")}
        };
        foreach (Student s in students)
        {
            context.Students.Add(s);
        }
        context.SaveChanges();

    }
}

MadeChanges in Startup.cs

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});
DbInitializer.Initialize(conetxt);

Package Manager Console> Add-Migration FirstMigration and after Database Update is completed

The problem arose in the "Database Update" command

+4
source share
1 answer

With EF Core, you now have two different command line tools: dotnet cli and the PM console . You can check the white papers for future reference.

dotnet CLI :

: dotnet ef migrations [] []

:

  • -h | --help = >
  • -v | --verbose = >

  • add = >
  • list = >
  • remove = >
  • script = > SQL script

, FirstMigration, :

>dotnet ef migrations add FirstMigration

:

  • Visual Studio 2017,
  • Visual Studio 2017, Install-Package Microsoft.EntityFrameworkCore.Tools -Pre. ( EF Core EF6 )

, :

>Add-Migration FirstMigration
+5

Source: https://habr.com/ru/post/1671499/


All Articles