在 biginning 中,我这样定义模型:
public class Category
{
public long CategoryId { get; set;}
public string CategoryName { get; set; }
public virtual ICollection<ContentInfo> Contents { get; set; }
}
Public class Article
{
public int ContentId { get; set; }
public string Content { get; set; }
[ForeignKey("Category")]
public long CategoryId { get; set; }
public virtual Category Category { get; set; }
}
使用 Automatic-Migration 从模型生成数据库后,我将 CategoryId 的类型从“long”更改为“int”,并再次使用 Automatic-Migration 更新数据库。
这次抛出异常,告诉我“CategoryId”列被Primary key和Foreign Key引用,所以迁移失败。如果我手动删除主键和外键,一切正常。但我希望自动迁移为我做这件事,可以吗?