Bug #67285 Support for EntityFramework 4.3 Code First Generated Identifiers
Submitted: 18 Oct 2012 11:53 Modified: 9 Jan 2015 9:49
Reporter: Øystein Strømme Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.6.3 OS:Microsoft Windows
Assigned to: Fernando Gonzalez.Sanchez CPU Architecture:Any
Tags: entityframework

[18 Oct 2012 11:53] Øystein Strømme
Description:
When using EntityFramework 4.3 and Code First the generated identifiers can get longer than 64 characters. When using MySQL Connector/Net this causes a MySQLException as foreign key identifiers are not truncated to be within the 64-character limit.

Relevant report on stackoverflow:
http://stackoverflow.com/questions/10368394/generated-identifier-too-long-for-constraint-n...

How to repeat:
Use Entity Framework 4.3 and Code First to create database.

Suggested fix:
Create (unique) truncated identfiers used in the 3 "ALTER TABLE"-statements when the database-schema is generated:
ProviderServices.cs:
MySqlProviderServices.GetAssociationCreateScript(AssociationType a)
[20 Feb 2013 0:03] John Russell
Added to changelog for 6.5.6, 6.6.6: 

When using EntityFramework 4.3 and Code First, generated foreign key
identifiers could be longer than 64 characters, causing
MySQLException errors. The fix renames any too-long identifiers using
the name format FK_guid, where guid is a global unique identifier
generated at runtime.
[15 Jan 2014 22:38] Marcelo Volmaro
Needs to be reopened for EF6. I'm getting the same error after I upgraded the connector from EF5 to EF6.
[16 Jan 2014 0:39] Fernando Gonzalez.Sanchez
Verified, happens again in Cnet 6.8 with EF6.

thanks for your bug report.

No need to open a new bug, progress will be tracked here.
[20 Jun 2014 14:40] Marcelo Volmaro
It would be nice if this can be fixed for 6.9...
[6 Oct 2014 22:10] Marcelo Volmaro
May we have a comment on this one? 6.9 is out and this bug is still there... it is quite annoying that I have to rename all my tables just for a bug in CNet...
[22 Oct 2014 0:27] Roberto Ezequiel Garcia Ballesteros
Hi Marcelo,

Fix is present in 6.9 also, so probably you need to re-create your FKs. The fix uses a GUID instead of table names for long names.

Regards,
Roberto
[10 Nov 2014 9:35] Yannic Staudt
Hello,

sadly the fix makes things worse in some cases; for example when removing a many to many relation, the migration will want to delete the foreign key indices prior to deleting the link table. This won't work because the connector has no way of identifying the foreign key (as it's "random").

I created another ticket here about that issue: #74726 / http://bugs.mysql.com/bug.php?id=74726

There's a fix proposal in there which works nicely here.
[18 Dec 2014 19:01] Marcelo Volmaro
This bug is NOT FIXED in 6.9.5.
I just hit this error again: "Identifier name 'FK_automatizaciones_objetosserializados_DatosPluginInputEntity_Id' is too long". I just deleted the word "Input" from the property name and things started to work again.

I can't believe this is still an issue, after two years and counting...
[14 Jan 2015 14:53] Marcelo Volmaro
I don't get it.. why this bug is closed? It is still there in the latest version..
[13 Feb 2015 0:51] Kevin Leeds
I'm using 6.9.5 - it seems to cut to the GUID on the UP method, but on the DOWN method it doesn't use that GUID name, it uses the long value name.

It also doesn't add semi-colons until the final migration statement, but that's another issue...