请考虑以下示例:
$table->unique(['site_id', 'inventory_items', 'lsd_location_id']);
然后抛出错误:
SQLSTATE[42000]:语法错误或访问冲突:1059标识符 名称 “lsd_location_units_site_id_inventory_items_lsd_location_id_unique”是 太长(SQL:alter table lsd_location_units 添加唯一的 lsd_location_units_site_id_inventory_items_lsd_location_id_unique ( site_id , inventory_items , lsd_location_id ))
lsd_location_units
lsd_location_units_site_id_inventory_items_lsd_location_id_unique
site_id
inventory_items
lsd_location_id
所以问题是:我能给它取一个不同的名字,并且保持它原来的唯一键吗,所以也许不是它的长名字: sid_ii_lsd_location_unuiqe 或者类似的?
sid_ii_lsd_location_unuiqe
(一) 在MYSQL中允许这样做吗?
(二) 有办法解决这个问题吗?因为我需要这三样东西。
目标是每个站点每个LSD位置id只有一个inventory_item_id。
第二个论点 unique 是索引键名称,请尝试:
unique
$table->unique(['site_id', 'inventory_items', 'lsd_location_id'], 'sid_ii_lsd_location_unuiqe');
来自拉勒维尔 docs : Laravel will automatically generate a reasonable index name, but you may pass a second argument to the method to specify the name yourself
Laravel will automatically generate a reasonable index name, but you may pass a second argument to the method to specify the name yourself
MySQL 5.6中的最大索引名称长度为64个字符( ref )