1
我有一个类,我想补充一些列如下:代码首先迁移
public partial class News : DbMigration
{
public override void Up()
{
AddColumn("dbo.News", "IsSchool", c => c.Boolean());
AddColumn("dbo.News", "City", c => c.String(maxLength: 200));
AddColumn("dbo.News", "County", c => c.String(maxLength: 200));
AddColumn("dbo.News", "SchoolName", c => c.String(maxLength: 200));
AddColumn("dbo.News", "VisitDatetime", c => c.DateTime());
Sql("UPDATE dbo.News SET IsSchool='false'");
}
public override void Down()
{
DropColumn("dbo.News", "VisitDatetime");
DropColumn("dbo.News", "County");
DropColumn("dbo.News", "City");
DropColumn("dbo.News", "IsSchool");
DropColumn("dbo.News", "SchoolName");
}
}
下面是配置:
public sealed class Configuration : DbMigrationsConfiguration<DataContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}
protected override void Seed(DataContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
}
}
我只是想运行此一次,看看是否数据库将得到更新?我怎样才能确保这个迁移运行?
我不得不数据库中没有接入和我的应用程序一直抱怨,IsSchool
字段为Nullable