[英]doctrine-behaviors translatable index identifier too long on mariadb
I'm using Symfony 4 with flex and tried to make some translation tables with the KNP Labs - Doctrine Behaviors but the index name auto generated by Symfony is too long for MariaDb. 我将Symfony 4与flex一起使用,并试图通过KNP Labs-Doctrine Behaviors创建一些翻译表,但是Symfony自动生成的索引名称对于MariaDb来说太长了。 At least I understand this from the error:
至少我从错误中了解到这一点:
In AbstractMySQLDriver.php line 125:
在AbstractMySQLDriver.php第125行中:
An exception occurred while executing
执行时发生异常
CREATE TABLE app_menu_trans (
id INT AUTO_INCREMENT NOT NULL,
translatable_id INT DEFAULT NULL,
name VARCHAR(255 ) NOT NULL,
locale VARCHAR(255) NOT NULL,
INDEX IDX_B79696A62C2AC5D3 (trans latable_id),
UNIQUE INDEX app_menu_trans_unique_translation (translatable_id, locale),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long;
SQLSTATE [42000]:语法错误或访问冲突:1071指定的密钥太长; max key length is 767 bytes
最大密钥长度为767字节
In PDOConnection.php line 109:
在PDOConnection.php第109行中:
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long;
SQLSTATE [42000]:语法错误或访问冲突:1071指定的密钥太长; max key length is 767 bytes
最大密钥长度为767字节
In PDOConnection.php line 107:
在PDOConnection.php第107行中:
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long;
SQLSTATE [42000]:语法错误或访问冲突:1071指定的密钥太长; max key length is 767 bytes
最大密钥长度为767字节
Something's fishy here, because MariaDb specs say that : 这里有些可疑,因为MariaDb规范说:
Databases, tables, columns, indexes, constraints, stored routines, triggers, events, views, tablespaces, servers and log file groups have an maximum length of 64 characters.
数据库,表,列,索引,约束,存储的例程,触发器,事件,视图,表空间,服务器和日志文件组的最大长度为64个字符。
I'm not advanced enough to understand what is wrong and how to get around it. 我还没有足够的知识来理解问题所在以及如何解决。
My Translation Table class below: 我的翻译表类如下:
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
* @ORM\Table(name="app_menu_trans")
* @ORM\Entity
*/
class MenuTranslation
{
use ORMBehaviors\Translatable\Translation;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*
* @return MenuTranslationTranslation
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
}
5 workarounds for the 767 error: http://mysql.rjweb.org/doc.php/limits#767_limit_in_innodb_indexes 5解决767错误的方法: http : //mysql.rjweb.org/doc.php/limits#767_limit_in_innodb_indexes
If you are hitting the limit because of trying to use CHARACTER SET utf8mb4. 如果由于尝试使用CHARACTER SET utf8mb4而达到极限。 Then do one of the following (each has a drawback) to avoid the error:
然后执行以下任一操作(每个操作都有一个缺点)来避免该错误:
⚈ Upgrade to 5.7.7 for 3072 byte limit -- your cloud may not provide this;
⚈ Change 255 to 191 on the VARCHAR -- you lose any values longer than 191 characters;
⚈ ALTER .. CONVERT TO utf8 -- you lose Emoji and some of Chinese;
⚈ Use a "prefix" index -- you lose some of the performance benefits.
Or... Stay with 5.6/5.5/10.1 but perform 4 steps to raise the limit to 3072 bytes: 或者...继续使用5.6 / 5.5 / 10.1,但执行4个步骤以将限制提高到3072字节:
SET GLOBAL innodb_file_format=Barracuda;
SET GLOBAL innodb_file_per_table=1;
SET GLOBAL innodb_large_prefix=1;
logout & login (to get the global values);
ALTER TABLE tbl ROW_FORMAT=DYNAMIC; -- (or COMPRESSED)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.