该模型已经具有相同名称的元素 - ASP.NET [英] The model already has an element that has the same name - ASP.NET

查看:2988
本文介绍了该模型已经具有相同名称的元素 - ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和ASP.Net Web应用程序的工作,每当我尝试添加 FOREIGN KEY 出现在数据工具操作这个错误:


  

SQL71508 ::该模型已经具有相同名称的元素
  dbo.FK_Sellers_Users。 SQL71508 ::该模型已经有一个元素
  具有相同名称dbo.FK_Sellers_Users


我不undearstand有什么用FK的问题!我有2个表,此错误

卖家

  CREATE TABLE [DBO]。[卖家](
    [Seller_ID] INT IDENTITY(1,1)NOT NULL,
    [名] NVARCHAR(50)NOT NULL,
    [SUsername] NVARCHAR(50)NOT NULL,
    [密码] NVARCHAR(50)NOT NULL,
    [SEmail] NVARCHAR(50)NOT NULL,
    [电话] NVARCHAR(50)NOT NULL,
    [城市] NVARCHAR(50)NOT NULL,
    [LastLoginDate] DATETIME NULL,
    [CreatedDate] DATETIME NULL,
    PRIMARY KEY CLUSTERED([Seller_ID] ASC)
    约束[FK_Sellers_Users]外键([SEmail])参考文献[用户]([邮件]),
    约束[FK_Sellers_Users]外键([SUsername])参考文献[用户]([用户名])
);

和表用户

  CREATE TABLE [DBO]。[用户](
    [ID] INT NOT NULL的身份,
    [用户名] NVARCHAR(50)NOT NULL,
    [密码] NVARCHAR(50)NOT NULL,
    [邮件] NVARCHAR(50)NOT NULL,
    [用户类型] INT NULL,
    PRIMARY KEY CLUSTERED([ID]),
    约束[AK_Users_Username] UNIQUE([用户名]),
    约束[AK_Users_Email] UNIQUE([邮件]),
);


解决方案

在dbo.Sellers在CREATE TABLE语句就在那里,你有两个FK约束命名FK_Sellers_Users。

请这些名字独特,也许是通过在结尾处添加列名。

I'm working with ASP.Net web application and whenever i tried to add a FOREIGN KEY this error appears in the Data tools operations :

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.

i don't undearstand what's the problem with FK ! i have 2 tables with this error

table Sellers :

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])
);

and table Users :

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]),
);

解决方案

Right there in your CREATE TABLE statement for dbo.Sellers, you have two FK constraints named FK_Sellers_Users.

Make those names unique, perhaps by adding the column name on the end.

这篇关于该模型已经具有相同名称的元素 - ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆