我正在嘗試填充流派表,但不斷收到錯誤消息:列名無效我有一個簡單的電影類型類模型。public class Genre{ public int Id { get; set; } public string Name { get; set; }}電影類與這樣的類型相關(guān)聯(lián):public class Movie{ public int Id { get; set; } [Required] public string Name { get; set; } [Required] public Genre Genre { get; set; } [Required] public DateTime ReleaseDate { get; set; } [Required] public DateTime DateAdded { get; set; } [Required] public int NumInStock { get; set; }}在我的 Nuget 控制臺中,我運(yùn)行add-migration并Genre為我生成了一個空表,其中包含兩列Id& name。然后,我嘗試使用此 SQL 查詢填充流派表:public override void Up(){ Sql("INSERT INTO Genres (Id, Name) VALUES (1, Fantasy)"); Sql("INSERT INTO Genres (Id, Name) VALUES (2, Drama)"); Sql("INSERT INTO Genres (Id, Name) VALUES (3, Action-Adventure)"); Sql("INSERT INTO Genres (Id, Name) VALUES (4, Foreign)"); Sql("INSERT INTO Genres (Id, Name) VALUES (5, Horror)"); Sql("INSERT INTO Genres (Id, Name) VALUES (6, Romance)"); Sql("INSERT INTO Genres (Id, Name) VALUES (7, Crime)"); Sql("INSERT INTO Genres (Id, Name) VALUES (8, Thriller)"); Sql("INSERT INTO Genres (Id, Name) VALUES (9, Animated)"); Sql("INSERT INTO Genres (Id, Name) VALUES (10, Western)");}不知道我做錯了什么。如果我將 'fantasy' 放在引號中(因?yàn)樗赡苄枰粋€字符串?)然后我收到這個錯誤:當(dāng) IDENTITY_INSERT 設(shè)置為 OFF 時,無法為表 'Genres' 中的標(biāo)識列插入顯式值。
SQL Server 更新數(shù)據(jù)庫的列名無效
人到中年有點(diǎn)甜
2021-08-07 18:07:19