Click here to Skip to main content
15,887,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
public override void Up()
  {
    Sql("INSERT INTO Workouts (Id, Name, Description) VALUES (1, 'HIIT', 'High-Intensity Interval Training​')");
    Sql("INSERT INTO Workouts (Id, Name, Description) VALUES (2, 'Yoga', 'Flexibility, relaxation, less stress')");
           
 }


What I have tried:

I run the code first migration. during update-database in package manager console, i got this error.

"Cannot insert explicit value for identity column in table 'table name' when IDENTITY_INSERT is set to OFF."
Posted
Updated 20-Sep-16 4:22am
Comments
[no name] 24-Nov-17 19:25pm    
Hello Karthik Bangalore, i have a problem with package manager control:
on this on :
public override void Up()
{
Sql("INSERT INTO MembershipTypes (Id, SignUpFee, DurationInMonths, DiscountRate) VALUES (1, 0, 0, 0)");
Sql("INSERT INTO MembershipTypes (Id, SignUpFee, DurationInMonths, DiscountRate) VALUES (2, 30, 1, 10)");
Sql("INSERT INTO MembershipTypes (Id, SignUpFee, DurationInMonths, DiscountRate) VALUES (3, 90, 3, 15)");
Sql("INSERT INTO MembershipTypes (Id, SignUpFee, DurationInMonths, DiscountRate) VALUES (4, 300, 12, 20)");
}
i have an error with package manager when i try to populate:
Cannot insert explicit value for identity column in table 'MembershipTypes' when IDENTITY_INSERT is set to OFF.

please i want hint

1 solution

Quote:
"Cannot insert explicit value for identity column in table 'table name' when IDENTITY_INSERT is set to OFF."

straight forward issue.
Id is an identity column, you cannot explicity insert identity value to the table directly,
You will have to set the IDENTITY_INSERT to ON to insert the id value.
SET IDENTITY_INSERT Workouts ON
 -- insert  the data 
INSERT INTO Workouts (Id, Name, Description) VALUES (1, 'HIIT', 'High-Intensity Interval Training​')   
 SET IDENTITY_INSERT Workouts OFF     
 
Share this answer
 
v2
Comments
wa.war 20-Sep-16 10:32am    
Thank you so much. You save my life again. :)
Karthik_Mahalingam 20-Sep-16 12:30pm    
no big words.
welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900