错误:
SqlException:当IDENTITY_INSERT设置为OFF时,无法为表'Recipe'中的Identity列插入显式值。
Program.cs
>>> import datetime
>>> import time
>>> timestamp = time.time()
>>> datetime.datetime.fromtimestamp(timestamp)
datetime.datetime(2018, 7, 22, 20, 10, 56, 241211)
>>> import pandas as pd
>>> series = pd.Series([1,5,7])
>>> datetime.datetime.fromtimestamp(series)
...
TypeError: cannot convert the series to <class 'int'>
>>>
我的数据库设计
Recipe Data这里应该是披萨。
答案 0 :(得分:0)
我知道这有点老了,但是对于任何看到此here is a link to the Microsoft Docs explaining how to fix it.
的人来说对于您的问题,您可以尝试通过打开和关闭身份证明插入框将保存的内容包围起来来解决此问题。
context.Database.OpenConnection();
try
{
context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Recipe ON");
context.SaveChanges();
context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Recipe OFF");
}
finally
{
context.Database.CloseConnection();
}