c# - ASP.NET MVC 5 中标识表和其他表之间的关系
问题描述
在 ASP.NET MVC 5 项目中,数据库和身份表首先由代码创建,我在这个数据库中通过 SQL(不是代码优先)创建了其他表,我想通过用户 ID 将用户表与某些表连接起来。
假设名为 Qwerty 的数据库和身份表是:
dbo.Users
dbo.Roles
dbo.UserClaims
... ect
我想通过 SQL 创建表,如下所示:
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
)
主题表创建成功,但是当我为书签表运行 SQL 代码时,它给我错误并用红线标记用户(表名)字
解决方案
默认情况下,用户的主键是 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
)
推荐阅读
- magento2 - 如何从尺寸样本中隐藏一些尺寸选项?
- python - 根据条件列值计算连续熊猫行的日期之间的差异
- visual-studio-code - VS Code 中 IntelliSense 中的本地图像
- php - 为什么我的 heroku 应用程序数据不断重置其数据?
- powershell - 是否可以通过 Powershell 在多个远程服务器上安装 Windows 更新?
- javascript - 在 Dyno Heroku 中,PostgreSQL 没有响应
- python - 无法在 matplotlib 文本中打印 $
- c++ - 复制构造函数,子类中的 operator=
- python - 尝试创建自定义颜色映射时出现类型错误
- linux - 如何加载新的配置文件?