2016-08-22 49 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數據連接來正常連接到新的數據庫,它工作。