VS Error: The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull
VS Error: The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull
我正在使用 Visual Studio 2015 与 Entity Framework 6 和 MySQL Server 5.7.13
mysql 服务器来自网络和 mysql 服务器在线托管服务,我使用 phpmyadmin 访问它。
当我尝试从数据库update/generate建模时出现以下错误(服务器连接成功)
Unable to generate the model because of the following exception: 'System.Data.StrongTypingException: The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull. ---> System.InvalidCastException: Specified cast is not valid.
at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey()
--- End of inner exception stack trace ---
at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey()
at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateProperties(IList`1 columns, IList`1 errors, List`1& keyColumns, List`1& excludedColumns, List`1& invalidKeyTypeColumns)
at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntityType(IList`1 columns, Boolean& needsDefiningQuery)
at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable`1 tableDetailsRows, EntityRegister entityRegister, IList`1 entitySetsForReadOnlyEntityTypes, DbObjectType objectType)
at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable`1 tableDetailsRowsForTables, IEnumerable`1 tableDetailsRowsForViews, EntityRegister entityRegister)
at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.Build(StoreSchemaDetails storeSchemaDetails)
at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.CreateStoreModel()
at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GenerateModel(List`1 errors)
at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String storeModelNamespace, ModelBuilderSettings settings, List`1 errors)
at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(ModelBuilderSettings settings, IVsUtils vsUtils, ModelBuilderEngineHostContext hostContext)'.
Loading metadata from the database took 00:00:00.6311313.
Generating the model took 00:00:01.9805600.
这个问题已被问及多次回答,大多数人同意以下任一解决方案都能解决问题:
- 降级到 MySQL 5.6
- 设置全局optimizer_switch='derived_merge=OFF'(需要超级权限)
- 设置@@optimizer_switch='derived_merge=OFF'
我与支持人员交谈(通过我的 phpmyadmin 工具)并请他们帮助我解决上述任一解决方案,这是他们的回复:
The MySQL version on all servers was very recently upgraded to MySQL 5.7.
Indeed, super user privileges are not available for your MySQL users.
Also, it is not technically possible to revert the MySQL version back to 5.6.
我进一步问他们为什么这些解决方案不可能,因为这些是我的问题的唯一已知解决方案,这是他们的最终答复:
Please note that your account is hosted on a shared hosting server,
and there are lots of other users whose accounts are located on the same server
where your account is hosted, hence we cannot globally turn off that feature,
as this would affect negatively the performance of the database server for
all the hosting accounts on the server (including your account as well).
所以我要向社区提出的最后一个问题是:这里的任何人都知道除上面列出的解决方案之外的任何解决方案(特定于我的情况和限制)?
由于我无法及时找到有效的解决方案,而且我的问题很紧急,所以我不得不寻找解决方法。
我使用了不同的mysql服务器托管平台并将我的数据库迁移到那里。它使用的是 MariaDB,因此 mysql 版本较低 (5.6)。
最后,我用Visual Studio数据连接正常连接到新数据库,成功了。
我遇到了同样的问题,并使用此处的答案解决了问题:
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';
我正在使用 Visual Studio 2015 与 Entity Framework 6 和 MySQL Server 5.7.13 mysql 服务器来自网络和 mysql 服务器在线托管服务,我使用 phpmyadmin 访问它。
当我尝试从数据库update/generate建模时出现以下错误(服务器连接成功)
Unable to generate the model because of the following exception: 'System.Data.StrongTypingException: The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull. ---> System.InvalidCastException: Specified cast is not valid. at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey() --- End of inner exception stack trace --- at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey() at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateProperties(IList`1 columns, IList`1 errors, List`1& keyColumns, List`1& excludedColumns, List`1& invalidKeyTypeColumns) at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntityType(IList`1 columns, Boolean& needsDefiningQuery) at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable`1 tableDetailsRows, EntityRegister entityRegister, IList`1 entitySetsForReadOnlyEntityTypes, DbObjectType objectType) at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable`1 tableDetailsRowsForTables, IEnumerable`1 tableDetailsRowsForViews, EntityRegister entityRegister) at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.Build(StoreSchemaDetails storeSchemaDetails) at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.CreateStoreModel() at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GenerateModel(List`1 errors) at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String storeModelNamespace, ModelBuilderSettings settings, List`1 errors) at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(ModelBuilderSettings settings, IVsUtils vsUtils, ModelBuilderEngineHostContext hostContext)'. Loading metadata from the database took 00:00:00.6311313. Generating the model took 00:00:01.9805600.
这个问题已被问及多次回答,大多数人同意以下任一解决方案都能解决问题:
- 降级到 MySQL 5.6
- 设置全局optimizer_switch='derived_merge=OFF'(需要超级权限)
- 设置@@optimizer_switch='derived_merge=OFF'
我与支持人员交谈(通过我的 phpmyadmin 工具)并请他们帮助我解决上述任一解决方案,这是他们的回复:
The MySQL version on all servers was very recently upgraded to MySQL 5.7. Indeed, super user privileges are not available for your MySQL users. Also, it is not technically possible to revert the MySQL version back to 5.6.
我进一步问他们为什么这些解决方案不可能,因为这些是我的问题的唯一已知解决方案,这是他们的最终答复:
Please note that your account is hosted on a shared hosting server, and there are lots of other users whose accounts are located on the same server where your account is hosted, hence we cannot globally turn off that feature, as this would affect negatively the performance of the database server for all the hosting accounts on the server (including your account as well).
所以我要向社区提出的最后一个问题是:这里的任何人都知道除上面列出的解决方案之外的任何解决方案(特定于我的情况和限制)?
由于我无法及时找到有效的解决方案,而且我的问题很紧急,所以我不得不寻找解决方法。
我使用了不同的mysql服务器托管平台并将我的数据库迁移到那里。它使用的是 MariaDB,因此 mysql 版本较低 (5.6)。
最后,我用Visual Studio数据连接正常连接到新数据库,成功了。
我遇到了同样的问题,并使用此处的答案解决了问题:
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';