MySQL Big FK identifier

懵懂的女人 提交于 2020-01-25 07:06:47

问题


I'm trying to create a fk but MySQL doesn't allow it ...

Identifier name 'foobarbaz_FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_PRODUCT_ENTITY' is too long [ CREATE TABLE `foobarbaz_weee_discount` (   `entity_id` int(10) unsigned NOT NULL DEFAULT '0',   `website_id` smallint(5) unsigned NOT NULL DEFAULT '0',   `customer_group_id` smallint(5) unsigned NOT NULL,   `value` decimal(12,4) NOT NULL DEFAULT '0.0000',   KEY `foobarbaz_FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_WEBSITE` (`website_id`),   KEY `foobarbaz_FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_PRODUCT_ENTITY` (`entity_id`),   KEY `foobarbaz_FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_GROUP` (`customer_group_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ]

Is there a way to add big fks? Thank you.


回答1:


No, it's hard coded into MySQL, see the docs (towards the bottom of the page). But it has nothing to do with the name of the FK. It's the name of the index that's too long (64 characters max):

`Identifier`                  `Maximum Length (characters)`
Database                      64
Table                         64
Column                        64
Index                         64
Constraint                    64
Stored Procedure or Function  64
Trigger                       64
View                          64
Alias                         256 (see exception following table)
Compound Statement Label      16



回答2:


I doubt it. You can try to change the datatype of the system table for foreign keys. However I never tried to change system tables before so no idea if there will be any complications if it is even possible.




回答3:


The foreign key is not the problem. It's the name of the key. I agree with MySQL, 'foobarbaz_FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_PRODUCT_ENTITY' is a bit silly :)

You have "PRODUCT_ENTITY" twice in the name. Start by dropping that :)




回答4:


It looks like this may be a bug. Here is the report that I found. I didn't see that it was patched yet but you can just rename your keys so that then length is shorter.

http://bugs.mysql.com/bug.php?id=13942



来源:https://stackoverflow.com/questions/4464714/mysql-big-fk-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!