I'm using EF code first DomesticTask class looks like
public class DomesticTask
{
public int Id { get; set; }
[Required]
public ApplicationUser DomesticClient { get; set; }
public DateTime DateTime { get; set; }
[Required]
[StringLength(500)]
public string Description { get; set; }
[Required]
public Category Category { get; set; }
}
Category Class is following
{
public int Id { get; set; }
[Required]
[StringLength(255)]
public string Name { get; set; }
}
DB context is following
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<DomesticTask> DomesticTasks { get; set; }
public DbSet<Category> Categories { get; set; }
and my migration class looks like this
public partial class PopulateCategoriesTable : DbMigration
{
public override void Up()
{
Sql("INSERT INTO Categories (Id, Name) VALUES (1, 'Plumber')");
Sql("INSERT INTO Categories (Id, Name) VALUES (2, 'Mason')");
Sql("INSERT INTO Categories (Id, Name) VALUES (3, 'Labour')");
Sql("INSERT INTO Categories (Id, Name) VALUES (4, 'Milk-man')");
Sql("INSERT INTO Categories (Id, Name) VALUES (5, 'Electrician')");
}
public override void Down()
{
Sql("DELETE FROM Categories WHERE Id IN (1, 2, 3, 4, 5)");
}
}
When I do update-database, it shows following error.
Error Number:544,State:1,Class:16 Cannot insert explicit value for identity column in table 'Categories' when IDENTITY_INSERT is set to OFF.
How do I resolve the error?