Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 强制条令创建类型=";guid";作为VARCHAR(255)而不是CHAR(36)_Mysql_Symfony_Doctrine Orm_Doctrine - Fatal编程技术网

Mysql 强制条令创建类型=";guid";作为VARCHAR(255)而不是CHAR(36)

Mysql 强制条令创建类型=";guid";作为VARCHAR(255)而不是CHAR(36),mysql,symfony,doctrine-orm,doctrine,Mysql,Symfony,Doctrine Orm,Doctrine,我正在尝试向我的Symfony项目添加一个新实体,该实体使用GUID字段映射到另一个实体: // OtherEntity /** * @ORM\Id * @ORM\Column(name="guid", type="guid", unique=true) */ protected $guid; // New Entity /** * @ORM\ManyToOne(targetEntity="OtherEntity") * @ORM\JoinColumn(name="other_

我正在尝试向我的Symfony项目添加一个新实体,该实体使用
GUID
字段映射到另一个实体:

// OtherEntity

/**
 * @ORM\Id
 * @ORM\Column(name="guid", type="guid", unique=true)
 */
protected $guid;


// New Entity

/**
 * @ORM\ManyToOne(targetEntity="OtherEntity")
 * @ORM\JoinColumn(name="other_guid", referencedColumnName="guid", nullable=false, onDelete="SET NULL")
 */
protected $otherEntity;
当使用
php应用程序/控制台时,条令转储以下SQL语句以创建
NewEntity
的表条令:schema:update--dump SQL

CREATE TABLE new_entity (guid CHAR(36) NOT NULL COMMENT '(DC2Type:guid)', other_guid CHAR(36) NOT NULL COMMENT '(DC2Type:guid)', ...

ALTER TABLE new_entity ADD CONSTRAINT FK_D3D1CD16A7FC4818 FOREIGN KEY (other_guid) REFERENCES other_entity (guid) ON DELETE SET NULL;
相反,当运行
doctrine:schema:update--force时,我得到以下错误:

[Doctrine\DBAL\Exception\DriverException]                                                                                                                                     
An exception occurred while executing 'ALTER TABLE new_entity ADD CONSTRAINT FK_D3D1CD16A7FC4818 FOREIGN KEY (other_guid) REFERENCES other_entity (guid) ON DELETE SET NULL':  
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint 
经过一番挖掘,我发现问题在于
type=“guid”
被翻译成
CHAR(36)
。如果改用
VARCHAR(255)
,一切正常

问题是,
other_entity
表的
guid
字段是
VARCHAR(255)
。因此,
new\u entity
中的
CHAR(36)
字段不能映射到其他类型的字段

我最近更新了我的Symfony项目:

doctrine/dbal               v2.4.4  --> 2.5.5
doctrine/doctrine-bundle    v1.2.0  --> 1.6.2           
doctrine/orm                v2.4.8  --> 2.5.5
symfony/symfony             v2.7.7  --> v2.8.12
运行
doctrine:schema:update
在旧配置下,将
GUID
字段创建为
VARCHAR(255)
,而新配置将其创建为
CHAR(36)

使用
CHAR(36)
是有意义的,因为这是guid的长度。但新格式带来了前面描述的问题:无法再映射到相同类型(guid)的旧字段

我不明白,为什么
条令:模式:更新
也不将现有字段更新为新格式


我能做些什么呢?要么强制条令将所有现有字段更新为
CHAR(36)
,要么继续创建
GUID
作为
VARCHAR(255)
尝试为相关字段指定相同的长度,并添加
选项={“fixed”=true}