【发布时间】:2014-04-14 08:07:30
【问题描述】:
我有一个 db 架构,并且我使用 EF6 代码先迁移。 我想将 dbo.aspnetuser 中的外键添加到我的数据库中的现有列(使用 MSSQL) 是否可以?怎么办?
将迁移文件更改为此,不起作用: 由于无法确定主键列,因此无法创建表“dbo.AspNetUsers”上具有“consumer_id”列的外键。使用 AddForeignKey fluent API 完全指定外键。
CreateTable(
"dbo.AspNetUsers",
c => new
{
Id = c.String(nullable: false, maxLength: 128),
UserName = c.String(),
PasswordHash = c.String(),
SecurityStamp = c.String(),
contact_firstname = c.String(),
contact_lastname = c.String(),
contact_phone = c.String(),
contact_phone2 = c.String(),
contact_email = c.String(),
country = c.String(),
state = c.String(),
city = c.String(),
street = c.String(),
postcode = c.String(),
longitude = c.Double(),
latitude = c.Double(),
consumer_id = c.Long(),
Discriminator = c.String(nullable: false, maxLength: 128),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.fx_service_consumers", t => t.consumer_id, cascadeDelete: true);
【问题讨论】:
标签: sql entity-framework ef-code-first