不知道我是否在這裏相同的網頁,但我認爲這就是你問。我有AutomaticMigrations設置爲false:
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
我有一個郵政類設置是這樣的:
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
[Required]
public DateTime DateCreated { get; set; }
public string Content { get; set; }
public string Tags { get; set; }
public ICollection<Comment> Comments { get; set; }
}
它已經產生,但後來我意識到,由於某種原因,我想需要稱號。
public class Post
{
public int Id { get; set; }
[Required]
public string Title { get; set; }
[Required]
public DateTime DateCreated { get; set; }
public string Content { get; set; }
public string Tags { get; set; }
public ICollection<Comment> Comments { get; set; }
}
我作出改變,做一個快速的構建,然後從PM控制檯I型:
添加遷移AddPostAnnotation(名稱可以是任何你想要的)
此生成此文件:
public partial class AddPostAnnotations : DbMigration
{
public override void Up()
{
AlterColumn("dbo.Posts", "Title", c => c.String(nullable: false));
}
public override void Down()
{
AlterColumn("dbo.Posts", "Title", c => c.String());
}
}
一旦在這裏,我只是從PM控制檯運行更新數據庫,併發送更改。
如何做到這一點,沒有AutomaticMigrationsEnabled = true選項? – 2012-02-10 08:55:05