Mid EF Core

How do you seed initial data using migrations / EF Core configuration?

Use the HasData() method in OnModelCreating():

modelBuilder.Entity<User>().HasData(

new User { Id = 1, Name = "Admin" }

  • Data is inserted automatically during Update-Database.
  • Changes to seed data require a new migration.

More from Entity Framework Core Tutorial

All questions for this course