【发布时间】:2016-09-27 21:29:44
【问题描述】:
这是迁移为我生成的代码:
public override void Up()
{
CreateTable(
"dbo.ApplicationUserProjects",
c => new
{
ApplicationUser_Id = c.String(nullable: false, maxLength: 128),
Project_ID = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.ApplicationUser_Id, t.Project_ID })
.ForeignKey("dbo.AspNetUsers", t => t.ApplicationUser_Id, cascadeDelete: true)
.ForeignKey("dbo.ProjectTbl", t => t.Project_ID, cascadeDelete: true)
.Index(t => t.ApplicationUser_Id)
.Index(t => t.Project_ID);
}
我将数据库名称更改为我更喜欢的名称,以及键名(列名)。示例数据库名称为“ProjectUsers”,Keys 为“ProjectID”和“UserID”。所以新代码如下所示:
CreateTable(
"dbo.ProjectUsers",
c => new
{
ProjectID = c.Int(nullable: false),
UserId = c.String(nullable: false, maxLength: 128),
})
.PrimaryKey(t => new { t.ProjectID, t.UserId })
.ForeignKey("dbo.ProjectTbl", t => t.ProjectID, cascadeDelete: true)
.ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
.Index(t => t.ProjectID)
.Index(t => t.UserId);
我通过运行迁移更新来更新数据库,表和所有内容都是使用我为数据库和键提供的名称创建的。但是当我导航到页面时,它说: 当我撤消对数据库名称的更改但保留我自己的名称作为它们的键时,也会发生同样的事情。
那么为什么会发生这种情况,不希望应用使用新名称的幕后发生了什么?
【问题讨论】:
标签: asp.net-mvc entity-framework-6 asp.net-identity-2 entity-framework-migrations