ASP.NET MVC 5 中身份表和其他表之间的关系
Relationship between Identity tables and Other tables in ASP.NET MVC 5
在 ASP.NET MVC 5 项目中,数据库和身份 table 首先由代码创建,我通过 SQL 创建其他 table(不是通过代码优先)在此数据库中,我想通过用户 ID 加入用户 table 和一些 table。
假设名为 Qwerty 的数据库和身份 table 是:
dbo.Users
dbo.Roles
dbo.UserClaims
... ect
我想通过 SQL 创建 table 像这样:
Create Table Topic.Topic
(
TopicID int Primary key identity(1,1) not null,
TopicAddress nvarchar(255) not null
)
Create Table dbo.Bookmark
(
BookmarkID int Primary key identity(1,1) not null,
BookmarkDate datetime default getdate() not null,
UserID int constraint FK_Favorites_Users_UserID foreign key (UserID) references Users(UserID) not null
)
主题 table创建成功,但是当我运行SQL书签table的代码时,它给了我错误并用 红线
标记 Users (table name) 单词
默认情况下Users的主键是nvarchar,所以你的外键应该定义成那个类型。
Create Table dbo.Bookmark
(
BookmarkID int Primary key identity(1,1) not null,
BookmarkDate datetime default getdate() not null,
UserID [nvarchar](128) constraint FK_Favorites_Users_UserID foreign key (UserID) references Users(UserID) not null
)
在 ASP.NET MVC 5 项目中,数据库和身份 table 首先由代码创建,我通过 SQL 创建其他 table(不是通过代码优先)在此数据库中,我想通过用户 ID 加入用户 table 和一些 table。
假设名为 Qwerty 的数据库和身份 table 是:
dbo.Users
dbo.Roles
dbo.UserClaims
... ect
我想通过 SQL 创建 table 像这样:
Create Table Topic.Topic
(
TopicID int Primary key identity(1,1) not null,
TopicAddress nvarchar(255) not null
)
Create Table dbo.Bookmark
(
BookmarkID int Primary key identity(1,1) not null,
BookmarkDate datetime default getdate() not null,
UserID int constraint FK_Favorites_Users_UserID foreign key (UserID) references Users(UserID) not null
)
主题 table创建成功,但是当我运行SQL书签table的代码时,它给了我错误并用 红线
标记 Users (table name) 单词默认情况下Users的主键是nvarchar,所以你的外键应该定义成那个类型。
Create Table dbo.Bookmark
(
BookmarkID int Primary key identity(1,1) not null,
BookmarkDate datetime default getdate() not null,
UserID [nvarchar](128) constraint FK_Favorites_Users_UserID foreign key (UserID) references Users(UserID) not null
)