2016-08-22 55 views
1

我正在使用Visual Studio 2015与实体框架6和MySQL服务器5.7.13 mysql服务器来自web和mysql服务器托管服务在线,并使用phpmyadmin访问它。VS错误:表'TableDetails'中列'IsPrimaryKey'的值是DBNull

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

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). 

所以,我对社会最后一个问题:这里有谁知道其它任何解决方案比上面列出的(特定于我的情况和限制)

回答

0

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

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

最后,我使用Visual Studio数据连接来正常连接到新的数据库,它工作。