【问题标题】:Azure Entity Framework AutomaticMigrationsEnabled changing datatype does not update database typeAzure Entity Framework AutomaticMigrationsEnabled 更改数据类型不会更新数据库类型
【发布时间】:2017-03-15 19:35:06
【问题描述】:

我正在尝试了解迁移。我有 AutomaticMigrationsEnabled = true;并创建了初始迁移。

如果我将新的 DBSet 添加到 DBContext 并发布此服务,则数据库将更新为可疑的相应新表。

但是,如果我更改实体类中某个属性的数据类型,例如在下面的示例中将 StatusID 从 int 更改为 string 并发布服务,则相应的列数据类型不会在数据库中更新。

如果 AutomaticMigrationsEnabled = true,那么为什么在这种情况下数据库不会自动更新?

谢谢

namespace myService.DataObjects
{
  public class Status : EntityData
  {
    public int StatusID { get; set; }
    public string Description { get; set; }
  }
}

public class myServiceContext : DbContext
{....
public Configuration()
{
  AutomaticMigrationsEnabled = true;
  AutomaticMigrationDataLossAllowed = true;
  SetSqlGenerator("System.Data.SqlClient", new EntityTableSqlGenerator());
}

【问题讨论】:

  • 您是否在每个属性中都遇到此问题,还是仅在 StatusID 中遇到此问题?像这样更改列类型通常涉及删除和重新创建列。 StatusID 是您的 PK,但在 Azure SQL(我猜测基于您使用 Azure SQL 的标签)中,没有 PK 就不能存在任何表。即使PK正在进行更改操作。您是否在日志中看到任何错误?
  • StatusID 不是主键,因为我从 EntityData 类继承主键是 EntityData 类的 ID。我会尝试更改其他属性,但我觉得它现在处于不稳定状态,我需要重置迁移以真正测试它,但我猜它正在发生在所有属性上。我一直在让它们保持同步时遇到问题,一分钟似乎可以工作,然后弹出这样的问题。
  • 嗯,它现在对我有用,我不确定我是否看到过去的事情或什么,但我将把它标记为已回答。感谢您花时间在此

标签: c# .net entity-framework azure azure-web-app-service


【解决方案1】:

它现在对我有用,我不确定我是否看到过去的东西或什么,但我会将其标记为已回答。感谢您花时间在此

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    • 2019-04-29
    相关资源
    最近更新 更多