我在尝试更新数据库时遇到问题。 我正在使用asp.net制作web-api。
我刚刚添加了新的迁移功能并且运行良好。然后使用update-database命令更新我的数据库。然后我改变了一些代码。当我添加新的迁移时,它说:
Unable to generate an explicit migration because the following explicit migrations are pending:
[201705310248355_changeProduct, 201706191007322_ModifyModel, 201707170631209_changeProductModel, 201707170652556_EditProductModelLagi, 201707180312064_AddStorageIdOnInventory, 201707190243206_ChangeRepository, 201708091124374_EditInventory, 201803130702299_testBoom].
Apply the pending explicit migrations before attempting to generate a new explicit migration.
但上次更新数据库时,它完美运行
PM> update-database -target testboom -startupprojectname ShopDiaryProject.EF -force
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is already at version 201803130702299_testBoom.
Soo,我尝试使用-force参数添加迁移。 它有效!
,但
我再次更新数据库,迁移内容喜欢从头开始,不能添加表。 以下是我的迁移:
public override void Up()
{
CreateTable(
"dbo.Categories",
c => new
{
Id = c.Guid(nullable: false),
Name = c.String(maxLength: 200),
Description = c.String(maxLength: 200),
UserId = c.Guid(nullable: false),
CreatedDate = c.DateTime(nullable: false),
ModifiedDate = c.DateTime(),
DeletedDate = c.DateTime(),
CreatedUserId = c.String(),
ModifiedUserId = c.String(),
DeletedUserID = c.String(),
IsDeleted = c.Boolean(nullable: false),
User_Id = c.String(maxLength: 128),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.AspNetUsers", t => t.User_Id)
.Index(t => t.User_Id);
CreateTable(
"dbo.Products",
c => new
{
Id = c.Guid(nullable: false),
Name = c.String(maxLength: 250),
BarcodeId = c.String(maxLength: 250),
CategoryId = c.Guid(nullable: false),
CreatedDate = c.DateTime(nullable: false),
ModifiedDate = c.DateTime(),
DeletedDate = c.DateTime(),
CreatedUserId = c.String(),
ModifiedUserId = c.String(),
DeletedUserID = c.String(),
IsDeleted = c.Boolean(nullable: false),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.Categories", t => t.CategoryId, cascadeDelete: true)
.Index(t => t.CategoryId);
CreateTable(
"dbo.Shopitems",
c => new
{
Id = c.Guid(nullable: false),
Quantity = c.Int(nullable: false),
price = c.Decimal(nullable: false, precision: 18, scale: 2),
ProductId = c.Guid(nullable: false),
ShoplistId = c.Guid(nullable: false),
CreatedDate = c.DateTime(nullable: false),
ModifiedDate = c.DateTime(),
DeletedDate = c.DateTime(),
CreatedUserId = c.String(),
ModifiedUserId = c.String(),
DeletedUserID = c.String(),
IsDeleted = c.Boolean(nullable: false),
})
并且它说数据库中已经有一个名为“Categories”的对象。 有什么想法吗?