EF 迁移 - 允许在单个迁移中丢失数据
EF Migrations - Allow Data Loss on a single migration
在 Entity Framework 迁移的 Configuration
中,您可以添加此行:
AutomaticMigrationDataLossAllowed = true;
这将允许在(例如)删除列时丢失数据。
有没有办法只对特定的迁移执行此操作?
即我不想永久设置此设置,但如果我搭建了一个有数据丢失的迁移,我想必须手动进入该迁移并执行如下操作:
public partial class removing_date_time : DbMigration
{
public override void Up()
{
Configuration.AutomaticMigrationDataLossAllowed = true;
//...
这可能吗?
你不能那样做。
因为 属性 用于 自动迁移 。您不能将其用于基于代码的迁移(即 Up()
和 Down()
).即属性属于DbMigrationsConfiguration
class.
您可以在此处阅读更多相关信息:AutomaticMigrationDataLossAllowed Property
在 Entity Framework 迁移的 Configuration
中,您可以添加此行:
AutomaticMigrationDataLossAllowed = true;
这将允许在(例如)删除列时丢失数据。
有没有办法只对特定的迁移执行此操作?
即我不想永久设置此设置,但如果我搭建了一个有数据丢失的迁移,我想必须手动进入该迁移并执行如下操作:
public partial class removing_date_time : DbMigration
{
public override void Up()
{
Configuration.AutomaticMigrationDataLossAllowed = true;
//...
这可能吗?
你不能那样做。
因为 属性 用于 自动迁移 。您不能将其用于基于代码的迁移(即 Up()
和 Down()
).即属性属于DbMigrationsConfiguration
class.
您可以在此处阅读更多相关信息:AutomaticMigrationDataLossAllowed Property