programing

MySQL-Entity : 'TableDetails'테이블의 'IsPrimaryKey'열 값이 DBNull입니다.

goodcopy 2021. 1. 16. 10:36
반응형

MySQL-Entity : 'TableDetails'테이블의 'IsPrimaryKey'열 값이 DBNull입니다.


Entity Framework 5 및 M ySQL Server 5.7.9함께 Visual Studio 2013사용 하고 있습니다.

데이터베이스에서 모델을 만들려고 할 때 ( 또는 ' 데이터베이스에서 모델 업데이트' ) 다음 메시지가 나타납니다.

'System.Data.StrongTypingException :'TableDetails '테이블의'IsPrimaryKey '열 값이 DBNull입니다. ---> System.InvalidCastException : 지정된 캐스트가 유효하지 않습니다.

이 질문이 이전에 요청되었음을 알고 있지만 해결책을 찾지 못했습니다. 또한 MySQL 5.6으로 다운 그레이드 할 수있는 옵션도 없습니다.

간단한 테이블에서도 문제가 발생합니다.

샘플 테이블

CREATE TABLE new_table
(
  id int(11) NOT NULL AUTO_INCREMENT,
  name varchar(45) NOT NULL,
  PRIMARY KEY (id)
) 
ENGINE = InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

테이블이 기본 키로 만 구성된 경우 모델이 생성되는 것입니다.

편집 : 두 필드를 모두 PRIMARY Keys로 만들면 모델이 오류없이 생성됩니다.

누구든지 이것에 대해 어떤 생각이 있습니까?

감사합니다.

전체 오류 스택 :

다음 예외로 인해 모델을 생성 할 수 없습니다. '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 columns, IList1 오류, 목록 1& keyColumns, List1 & excludedColumns, 목록1& invalidKeyTypeColumns) at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntityType(IList1 열 및 부울 needsDefiningQuery) Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets (는 IEnumerable에서 1 tableDetailsRows, EntityRegister entityRegister, IListMicrosoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets에서 1 entitySetsForReadOnlyEntityTypes을 DbObjectType objectType의 ()을 IEnumerable 1 tableDetailsRowsForTables, IEnumerable1 tableDetailsRowsForViews , EntityRegister entityRegister)의 Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.Build (StoreSchemaDetails)의 Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.CreateStoreModel ()의 Microsoft.Data.Entity .Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GenerateModel (List1 errors) at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String storeModelNamespace, List1 오류) Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel (EdmxHelper edmxHelper) '에 있습니다. 데이터베이스에서 메타 데이터를로드하는 데 00 : 00 : 00.5856317이 걸렸습니다.


Entity Framework (버전 6.1.3) 및 MySQL Server (> = 5.7.6)

문제를 해결하는 한 가지 방법은

1. Open Services (services.msc) and restart MySQL57 service.
2. Execute the following commands in MySQL.
   use <<database name>>;
   set global optimizer_switch='derived_merge=OFF';
3. Update the .edmx.

답변이 늦었습니다. 그러나 그것이 누군가를 도울 수 있기를 바랍니다.

감사.


이것은 알려진 버그입니다 : http://bugs.mysql.com/bug.php?id=79163

mysql 콘솔에서 명령을 실행합니다.

전역 optimizer_switch = 'derived_merge = off'설정

또는

@@ optimizer_switch = 'derived_merge = OFF'설정

(이것은 나를 위해 일했습니다)

다음 명령으로 변경 사항이 적용되는지 확인하십시오.

@@ optimizer_switch \ G 선택

https://dev.mysql.com/doc/refman/5.7/en/switchable-optimizations.html


위의 모든 답변은 잘 작동하지만 서버 또는 dev-machine이 다시 시작되면 모든 단계를 반복해서 수행해야합니다. 완전히 해결하기 위해 mysql 구성에이 속성 'derived_merge = OFF'를 넣을 수 있습니다. 그러려면 MySQL Workbench를 사용하여 MySQL 서버에 액세스하고 "옵션 파일"> 성능 선택 탭을 열어야합니다. Optimizer 그룹에서 optimizer_switch를 찾고 확인란을 클릭하여 필드를 활성화 한 다음 'derived_merge = OFF'를 입력합니다. services.msc 및 voilá에서 서버를 다시 시작하십시오!


다음 SQL이 저에게 효과적이었습니다.

use adventureworks;
set global optimizer_switch='derived_merge=off';
set optimizer_switch='derived_merge=off';

select @@optimizer_switch;
select @@GLOBAL.optimizer_switch;

내 MySQL 버전은 5.7.15이고 Visual Studio 2015의 "EF Designer From Database"옵션을 사용했습니다.

다른 사람들에게 도움이되기를 바랍니다. :)


해결 방법 SET GLOBAL optimizer_switch = 'derived_merge = off';


'TableDetails'테이블의 'IsPrimaryKey'열 값은 DBNull입니다.

That's what happens when you try to use MySql among with Entity Framework.

I have solved this way:

Open MySQL 5.7 Command Line Client, type your password, press enter and then type:

set global optimizer_switch='derived_merge=off';
set optimizer_switch='derived_merge=off';

select @@optimizer_switch;
select @@GLOBAL.optimizer_switch;

Reboot Visual Studio you're good to go, I've tried with VS 2013 and VS 2017, and worked in both!


Run this script, it worked perfectly for me while using MySql.Data.Entity nugget package

use YourDB;
   set global optimizer_switch='derived_merge=OFF';

We've encountered same error. But,I think this is MySQL's server problem.

status:

  • EF5
  • MySQL VS Tools 1.2.5
  • VS community 2015
  • C#
  • from Database create EF Designer(I'm using japanese edition,so menu name is my english...)

result:

  • MySQL 5.7.9 => error.
  • MySQL 5.6.26 => no error.

In my case:

Modules Used:

Entity Framework 6 MySql Data Connector 6.9.9 MySQL VS Tools 1.2.6 EF6 Tools for VS2015

I have to do this => SET GLOBAL optimizer_switch='derived_merge=off'; But if loggin with "root" user the error continues. When loggin with "common" user, it create the model OK.


From today, this is a verified MySql Community Server 5.7.9 bug with ID 79163.

As a workaround, i reshaped the application to use Code First practise

(ADO.NET Entity Data Object -> Empty Code First model)

and manually added all the objects and their properties.

Modules Used:

  • Entity Framework 6
  • MySql Data Connector 6.8.9
  • MySQL VS Tools 1.2.5
  • EF6 Tools for VS2013

i have found a good workaround for this type of error.

1. Solution ( database first) Instead of trying to update the existing model in the .edmx File, right-click one of your entities in edmx and choose -> go to modelbrowser ( a new register appears in the project map explorer). Now choose the entity you want to update , right-click and do the update. In my case it worked every time without the need to switch anything off in mysql. But it may happen that you will be forced to change some relationships manually. If anything gets wrong here ( in my case there are no problems with non fk / pk key. If you delete a fk and try to order all relationsships by yourself your db might be dropped. But this never occures if you just update not primary / foreign key attributes or just adding a new table.

EDIT: This Solution works great for deleting, updating and adding new relations. It causes problems when updates are performed on fk /pk attributes!

If your table has been dropped so just create a new one with same preferences.

2. Solution (database first, when pk / fk keys must be updated) drop the table and create a new one. This takes 3 min all together

I hope i could help a little bit, this bug drove me crazy the past 2 weeks !

p.s. i did never experienced this type of bug until i have overwritten! a foreign key in an existing relation in mysql. Then i tried to update the relation with entity framework (database first) and since then on the dbNullBug appeared. I was able to manage my entities manually by adding and removing existing attributes but it was really exhausting. The solution 1 works well for me and if i need to update foreign key i just drop the existing Model and create a new one.

ReferenceURL : https://stackoverflow.com/questions/33575109/mysql-entity-the-value-for-column-isprimarykey-in-table-tabledetails-is

반응형