我有一個ASP.NET身份2.0和數據庫的項目,由ASP.NET身份1.0創建。我想更新我的數據庫。我執行以下操作:更新ASP.NET身份
- 啓用遷移:
啓用的遷移-ProjectName網絡
察看此背景下針對現有的數據庫...
的Code First爲項目Web啓用遷移。
- 添加遷移(我的項目有2個連接字符串,我選擇合適的,與 '舊' 的數據庫表):
添加遷移-Name UpdateIdentity -ProjectName Web -ConnectionStringName MainContext
腳手架遷移'UpdateIdentity'。
此遷移文件的設計器代碼包含當前Code First型號的 的快照。當您搭建下一個遷移時,此快照用於計算對您的模型的更改 。如果您對 遷移中包含的模型進行了其他更改,那麼您可以通過再次運行「添加遷移 UpdateIdentity」來對其進行重新腳手架搭建。
,但它會生成以下腳本:
public override void Up()
{
CreateTable(
"dbo.AspNetRoles",
c => new
{
Id = c.String(nullable: false, maxLength: 128),
Name = c.String(nullable: false, maxLength: 256),
})
.PrimaryKey(t => t.Id)
.Index(t => t.Name, unique: true, name: "RoleNameIndex");
CreateTable(
"dbo.AspNetUserRoles",
c => new
{
UserId = c.String(nullable: false, maxLength: 128),
RoleId = c.String(nullable: false, maxLength: 128),
})
.PrimaryKey(t => new { t.UserId, t.RoleId })
.ForeignKey("dbo.AspNetRoles", t => t.RoleId, cascadeDelete: true)
.ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
.Index(t => t.UserId)
.Index(t => t.RoleId);
CreateTable(
"dbo.AspNetUsers",
c => new
{
Id = c.String(nullable: false, maxLength: 128),
CompanyId = c.Int(nullable: false),
SMSnumber = c.String(),
FullName = c.String(),
Email = c.String(maxLength: 256),
EmailConfirmed = c.Boolean(nullable: false),
PasswordHash = c.String(),
SecurityStamp = c.String(),
PhoneNumber = c.String(),
PhoneNumberConfirmed = c.Boolean(nullable: false),
TwoFactorEnabled = c.Boolean(nullable: false),
LockoutEndDateUtc = c.DateTime(),
LockoutEnabled = c.Boolean(nullable: false),
AccessFailedCount = c.Int(nullable: false),
UserName = c.String(nullable: false, maxLength: 256),
})
.PrimaryKey(t => t.Id)
.Index(t => t.UserName, unique: true, name: "UserNameIndex");
CreateTable(
"dbo.AspNetUserClaims",
c => new
{
Id = c.Int(nullable: false, identity: true),
UserId = c.String(nullable: false, maxLength: 128),
ClaimType = c.String(),
ClaimValue = c.String(),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
.Index(t => t.UserId);
CreateTable(
"dbo.AspNetUserLogins",
c => new
{
LoginProvider = c.String(nullable: false, maxLength: 128),
ProviderKey = c.String(nullable: false, maxLength: 128),
UserId = c.String(nullable: false, maxLength: 128),
})
.PrimaryKey(t => new { t.LoginProvider, t.ProviderKey, t.UserId })
.ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
.Index(t => t.UserId);
}
它試圖從零創建表,但我需要一個腳本來修改。爲什麼如此以及如何創建正確的腳本?
它創建一個空遷移 –
是的,'-IgnoreChanges'告訴EF只捕獲沒有Up()代碼的模型。在更改模型或升級身份之前,請先執行此操作。然後'update-database'應用它。現在,升級到Identity 2,第二次遷移將與所需的更改有所不同。 –