I try to add a class and apply add-migration to update database but the migration script generated is up and down empty.
我尝试添加一个类并应用add-migration来更新数据库,但生成的迁移脚本是空的。
I have deleted migration history table and update database, then apply modifications to my model by adding new class and generate add-migration script but it's KO.
我删除了迁移历史记录表和更新数据库,然后通过添加新类并生成添加迁移脚本来对我的模型应用修改,但它是KO。
Really strange is when I add a property to an existing class, add-migration detect the changes and the script generated is not empty.
非常奇怪的是,当我向现有类添加属性时,add-migration会检测更改并且生成的脚本不为空。
please help
1 个解决方案
#1
I had the same problem . I think you have to pay attention to your mapping . may be your relation is with type of HasRequired which should be changed to hasOptional. Sample => Mapping with Mistake :
我有同样的问题 。我想你必须注意你的映射。可能是你的关系是HasRequired的类型,应该改为hasOptional。 Sample =>错误映射:
this.HasRequired(t => t.Term)
.WithMany(t => t.UserDemands)
.HasForeignKey(d => d.TermId);
Correct Mapping :
正确的映射:
this.HasOptional(t => t.Term)
.WithMany(t => t.UserDemands)
.HasForeignKey(d => d.TermId);
#1
I had the same problem . I think you have to pay attention to your mapping . may be your relation is with type of HasRequired which should be changed to hasOptional. Sample => Mapping with Mistake :
我有同样的问题 。我想你必须注意你的映射。可能是你的关系是HasRequired的类型,应该改为hasOptional。 Sample =>错误映射:
this.HasRequired(t => t.Term)
.WithMany(t => t.UserDemands)
.HasForeignKey(d => d.TermId);
Correct Mapping :
正确的映射:
this.HasOptional(t => t.Term)
.WithMany(t => t.UserDemands)
.HasForeignKey(d => d.TermId);