The full error:
(完整错误:)
System.Data.SqlClient.SqlException : the UPDATE statement conflicted with the FOREIGN KEY constraint \"FK__Product__Categor__1FCDBCEB\".
(System.Data.SqlClient.SqlException :UPDATE语句与FOREIGN KEY约束\“ FK__Product__Categor__1FCDBCEB \”冲突。)
The conflict occurred in database \"dbi416547_i416547\", table \"dbo.Category\", column 'CategoryID'. (数据库\“ dbi416547_i416547 \”,表\“ dbo.Category \”的列“ CategoryID”中发生了冲突。)
Now I tried looking it up and found: Sql error on update : The UPDATE statement conflicted with the FOREIGN KEY constraint
(现在,我尝试查找它并发现: 更新时出现SQL错误:UPDATE语句与FOREIGN KEY约束冲突)
But I don't know how to modify the foreign key in visual studio 2019. Also I don't understand where I would put the rule using T-SQL, because my table goes like:
(但是我不知道如何在Visual Studio 2019中修改外键。而且我也不知道如何使用T-SQL将规则放在哪里,因为我的表如下所示:)
CREATE TABLE [dbo].[Product]
(
[ProductID] INT IDENTITY (1, 1) NOT NULL,
[UserID] INT NOT NULL,
[Name] NVARCHAR(50) NOT NULL,
[Price] DECIMAL(18) NOT NULL,
[Description] NVARCHAR(50) NOT NULL,
[CategoryID] INT NOT NULL,
[Photo] NVARCHAR(50) NULL,
[Likes] INT NULL,
PRIMARY KEY CLUSTERED ([ProductID] ASC),
FOREIGN KEY ([UserID]) REFERENCES [dbo].[User] ([UserID]),
FOREIGN KEY ([CategoryID]) REFERENCES [dbo].[Category] ([CategoryID])
);
And if I put it underneath or between the ( ) I still get errors.
(而且,如果将其放在()下方或之间,我仍然会出错。)
Any suggestions? (有什么建议么?)
ask by Zheng-rong Cai translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…