【问题标题】:VS Error: The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNullVS 错误:表 'TableDetails' 中列 'IsPrimaryKey' 的值为 DBNull
【发布时间】:2016-12-28 12:03:35
【问题描述】:

我正在使用带有实体框架 6 和 MySQL 服务器 5.7.13 的 Visual Studio 2015 mysql服务器来自一个web和mysql服务器在线托管服务,我使用phpmyadmin访问它。

当我尝试从数据库更新/生成模型时出现以下错误(服务器连接成功)

由于以下异常,无法生成模型:“System.Data.StrongTypingException:表“TableDetails”中“IsPrimaryKey”列的值为 DBNull。 ---> System.InvalidCastException:指定的强制转换无效。
   在 Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey()
   --- 内部异常堆栈跟踪结束 ---
   在 Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey()
   在 Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateProperties(IList`1 列,IList`1 错误,List`1& keyColumns,List`1&excludedColumns,List`1& invalidKeyTypeColumns)
   在 Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntityType(IList`1 列,布尔和需要定义查询)
   在 Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable`1 tableDetailsRows,EntityRegister entityRegister,IList`1 entitySetsForReadOnlyEntityTypes,DbObjectType objectType)
   在 Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable`1 tableDetailsRowsForTables,IEnumerable`1 tableDetailsRowsForViews,EntityRegister entityRegister)
   在 Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.Build(StoreSchemaDetails storeSchemaDetails)
   在 Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.CreateStoreModel()
   在 Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GenerateModel(列表`1 错误)
   在 Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(字符串 storeModelNamespace,ModelBuilderSettings 设置,List`1 错误)
   在 Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(ModelBuilderSettings 设置,IVsUtils vsUtils,ModelBuilderEngineHostContext hostContext)'。
从数据库加载元数据耗时 00:00:00.6311313。
生成模型耗时 00:00:01.9805600。

这个问题已经被问了好几次了,并且回答了好几次,大多数人都同意这些解决方案中的任何一个都可以解决这个问题:
- 降级到 MySQL 5.6
- 设置全局 optimizer_switch='derived_merge=OFF'(需要超级权限
- 设置@@optimizer_switch='derived_merge=OFF'

我与支持人员(通过我的 phpmyadmin 工具)进行了交谈,并要求他们帮助我解决上述任一解决方案,这是他们的回复:

所有服务器上的 MySQL 版本最近都升级到了 MySQL 5.7。 事实上,您的 MySQL 用户无法使用超级用户权限。 此外,从技术上讲,无法将 MySQL 版本恢复到 5.6。

我进一步问他们为什么这些解决方案不可能,因为这些是解决我的问题的唯一已知解决方案,这是他们的最终答复:

请注意,您的帐户托管在共享托管服务器上, 并且有很多其他用户的帐户位于同一台服务器上 您的帐户所在的位置,因此我们无法全局关闭该功能, 因为这会对数据库服务器的性能产生负面影响 服务器上的所有托管帐户(包括您的帐户)。

所以我向社区提出的最后一个问题:这里的任何人都知道除了上面列出的解决方案(特定于我的情况和限制)之外的任何解决方案

【问题讨论】:

    标签: c# mysql entity-framework visual-studio phpmyadmin


    【解决方案1】:

    我遇到了同样的问题并使用此处的答案解决了:

    https://bugs.mysql.com/bug.php?id=79163#c445530

    在 MySQL 中

    use <<database name>>;
    set global optimizer_switch='derived_merge=off';
    set optimizer_switch='derived_merge=off';
    

    【讨论】:

      【解决方案2】:

      由于无法及时找到有效的解决方案,而且我的问题很紧迫,我不得不寻找解决方法。

      我使用了一个不同的 mysql 服务器托管平台并将我的数据库迁移到那里。它使用的是 MariaDB,因此 mysql 版本较低(5.6)。

      最后,我使用Visual Studio数据连接正常连接到新数据库,并且成功了。

      【讨论】:

        猜你喜欢
        • 2014-04-20
        • 1970-01-01
        • 2014-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多