gpt4 book ai didi

sql - 该模型已有一个同名元素 - ASP.NET

转载 作者:太空狗 更新时间:2023-10-30 01:56:27 25 4
gpt4 key购买 nike

我正在使用 ASP.Net Web 应用程序,每当我尝试添加 FOREIGN KEY 时,数据工具操作中都会出现此错误:

SQL71508 :: The model already has an element that has the same name dbo.FK_Sellers_Users. SQL71508 :: The model already has an element that has the same name dbo.FK_Sellers_Users.

我不明白FK有什么问题!我有 2 个表有这个错误

卖家:

CREATE TABLE [dbo].[Sellers] (
[Seller_ID] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (50) NOT NULL,
[SUsername] NVARCHAR (50) NOT NULL,
[Password] NVARCHAR (50) NOT NULL,
[SEmail] NVARCHAR (50) NOT NULL,
[Phone] NVARCHAR (50) NOT NULL,
[City] NVARCHAR (50) NOT NULL,
[LastLoginDate] DATETIME NULL,
[CreatedDate] DATETIME NULL,
PRIMARY KEY CLUSTERED ([Seller_ID] ASC),
CONSTRAINT [FK_Sellers_Users] FOREIGN KEY ([SEmail]) REFERENCES [Users]([Email]),
CONSTRAINT [FK_Sellers_Users] FOREIGN KEY ([SUsername]) REFERENCES [Users]([Username])
);

和表用户:

CREATE TABLE [dbo].[Users] (
[Id] INT NOT NULL IDENTITY,
[Username] NVARCHAR (50) NOT NULL,
[Password] NVARCHAR (50) NOT NULL,
[Email] NVARCHAR (50) NOT NULL,
[UserType] INT NULL,
PRIMARY KEY CLUSTERED ([Id]),
CONSTRAINT [AK_Users_Username] UNIQUE ([Username]),
CONSTRAINT [AK_Users_Email] UNIQUE ([Email]),
);

最佳答案

在 dbo.Sellers 的 CREATE TABLE 语句中,您有两个名为 FK_Sellers_Users 的 FK 约束。

使这些名称唯一,可以在末尾添加列名。

关于sql - 该模型已有一个同名元素 - ASP.NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32082167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com