迁移期间不会创建新表。
迁移本身似乎是创建的
public partial class _222 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ToDos",
columns: table => new
{
Id = table.Column<string>(nullable: false),
Name = table.Column<string>(nullable: true),
Body = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ToDos", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ToDos");
}
}
但是当我写 Update-Database 表时没有创建。
ApplicationDbContext
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
Database.EnsureCreated();
}
public DbSet<ToDo> ToDos { get; set; }
全部
public class ToDo
{
[Key]
public string Id { get; set; }
public string Name { get; set; }
public string Body { get; set; }
}
来自包管理器控制台中的错误
Failed executing DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [AspNetRoles] (
[Id] nvarchar(450) NOT NULL,
[Name] nvarchar(256) NULL,
[NormalizedName] nvarchar(256) NULL,
[ConcurrencyStamp] nvarchar(max) NULL,
CONSTRAINT [PK_AspNetRoles] PRIMARY KEY ([Id])
);
There is already an object named 'AspNetRoles' in the database.
红糖糍粑
相关分类