EF6 MySql - All parts of a key must be non-nullable

entity-framework-6 mysql


So this is a new error that just start coming up for me and I'm not sure why. When I try to add a table through EF6, I get the following errors on any fields that are non-nullable. On tables that I have been able to add, if I open the edmx file in XML, I can see that the [Key] section for each table in the StorageSection contains every field in the table. So this is clearly a bug somewhere, but I'm not sure where.

I've done the following: - Double-checked my data model in MySql (using version 5.7.7) - Uninstalled and reinstalled Visual Studio 2015 - Uninstalled and reinstalled Entity Framework (version 6.1.3) - Using the Devart dotConnect MySql Pro Trial (version 8.6.677.0) - Double-checked all web.config options to make sure they are correct.

Sample Error: Error 13101: Key part 'LockOutEndDateUtc' for type 'aspnetusers' is not valid. All parts of the key must be non-nullable. HRSMonitor C:\Users\Kevin\Documents\Visual Studio 2015\Projects\HRSMonitor\HRSMonitor\Models\dbHRS.edmx

Here's the create table script for the aspnetusers table:

'aspnetusers', 'CREATE TABLE aspnetusers ( Id varchar(128) NOT NULL, Email varchar(256) DEFAULT NULL, EmailConfirmed tinyint(4) DEFAULT NULL, PasswordHash varchar(21000) DEFAULT NULL, SecurityStamp varchar(21000) DEFAULT NULL, PhoneNumber varchar(21000) DEFAULT NULL, PhoneNumberConfirmed tinyint(1) DEFAULT NULL, TwoFactorEnabled tinyint(1) DEFAULT NULL, LockOutEndDateUtc datetime DEFAULT NULL, LockoutEnabled bit(1) DEFAULT NULL, AccessFailedCount int(11) DEFAULT NULL, UserName varchar(256) NOT NULL, PRIMARY KEY (Id), KEY Id (Id)) ENGINE=InnoDB DEFAULT CHARSET=latin1'

Any ideas would be greatly appreciated.

7/16/2016 1:42:33 PM

Popular Answer

Found my problem, in MySql, the following statements need to be run and then EF6 cooperates:

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

7/16/2016 2:04:31 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow