Bug #71282 Error when inserting data using entity framework 6 on mysql 5.6
Submitted: 2 Jan 2014 22:29 Modified: 7 Feb 2014 22:26
Reporter: Garvin Casimir Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.8.3 OS:MacOS
Assigned to: CPU Architecture:Any
Tags: Code First, entity framework, migrations

[2 Jan 2014 22:29] Garvin Casimir
Description:
I setup my code for entityframework 6 code first migrations but get the following error when the code attempts to insert the initial data into my database:

 MySql.Data.MySqlClient.MySqlException : Specified key was too long; max key length is 767 bytes
  at MySql.Data.MySqlClient.MySqlStream.ReadPacket () [0x00000] in <filename unknown>:0 
  at MySql.Data.MySqlClient.NativeDriver.GetResult (System.Int32& affectedRow, System.Int64& insertedId) [0x00000] in <filename unknown>:0 

Note that I do not get this error in Msql 5.1 using the same setup.

Here is a result of the 'explain people;' command on my local machine which has 5.1 installed. I just don't see anything that would cause this error.

mysql> explain people;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| PersonID    | int(11)      | NO   | PRI | NULL    | auto_increment | 
| FirstName   | varchar(100) | YES  |     | NULL    |                | 
| LastName    | varchar(100) | YES  |     | NULL    |                | 
| DateOfBirth | datetime     | NO   |     | NULL    |                | 
| Children    | int(11)      | NO   |     | NULL    |                | 
+-------------+--------------+------+-----+---------+----------------+

How to repeat:
Project: https://github.com/garvincasimir/csharp-parameterized-query-builder

Entity Framework POCO: https://github.com/garvincasimir/csharp-parameterized-query-builder/blob/master/Parameteri...

Seed Class (initial data) : https://github.com/garvincasimir/csharp-parameterized-query-builder/blob/master/Parameteri...

To repeat:
 Download and build the project and run the tests against mysql v5.6

Mysql connection string is in this file: https://github.com/garvincasimir/csharp-parameterized-query-builder/blob/master/Parameteri...

Here is a link to a travis failed build:
https://travis-ci.org/garvincasimir/csharp-parameterized-query-builder/builds/16188403

Here is a link to a build which passes when i go to mysql 5.1: https://travis-ci.org/garvincasimir/csharp-parameterized-query-builder/jobs/16281899
[6 Jan 2014 23:23] Roberto Ezequiel Garcia Ballesteros
Hi Garvin,

This error is because the default behavior for history table creates a composed primary key (using 2 columns). You can solve this using MySqlEFConfiguration class. It's important to create the instance of your context class as the first step in your code.

You can find more information here:

http://dev.mysql.com/doc/refman/5.6/en/connector-net-entityframework60.html

Regards.
[6 Jan 2014 23:55] Garvin Casimir
Ah, so the error has nothing to do with my actual application schema. If I use the MySqlEFConfiguration class then I can't use the dbconfig method to seed my data. I tried subclassing it but I got an error about the history configuration class not being in the same assembly as the dbconfig class. I guess I need to play around with this a little more.
[7 Jan 2014 22:26] Roberto Ezequiel Garcia Ballesteros
Garvin,

What MySqlEFConfiguration does to solve this problem is overriding history table operation to create only one column in the primary table instead of two. You can do the same (avoiding using MySqlEFConfiguration) using the following code inside your DbConfiguration class:

SetHistoryContext(MySqlProviderInvariantName.ProviderName, (existingConnection, defaultSchema) => new MySqlHistoryContext(existingConnection, defaultSchema));

Hope this helps.

Regards,
Roberto
[8 Feb 2014 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".