我遇到了
的问题/**
* @package Entity
* @ORM\Entity
* @ORM\Table(name="r_country")
*/
class RCountry {
/**
* @ORM\Column(type="string", length=2)
* @ORM\Id
*/
protected $id;
...
/**
*
* @ORM\ManyToMany(targetEntity="RLanguage")
* @ORM\JoinTable(name="prohibited_language_display",
* joinColumns={@ORM\JoinColumn(name="country_id", referencedColumnName="id", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="language_id", referencedColumnName="id", onDelete="CASCADE")}
* )
*
*/
protected $prohibitedLanguageDisplay;
...
}
/**
* @package Entity
* @ORM\Entity
* @ORM\Table(name="r_language")
*/
class RLanguage
{
/**
* @ORM\Column(type="string", length=20)
* @ORM\Id
*
*/
protected $id;
...
}
我试图与教条做一个ManyToMany关系,但当我做更新时会触发错误
[学说\ DBAL \异常\ DriverException]
执行' ALTER TABLE时发生异常 prohibited_language_display ADD CONSTRAINT FK_77B02D13F92F3E70 FOREIGN KEY(country_id)参考r_country(id)ON DELETE CASCADE':
SQLSTATE [HY000]:常规错误:1005无法创建表 '数据库#SQL-498_8797' (错误:150)[Doctrine\DBAL\Driver\PDOException]
SQLSTATE [HY000]:常规错误:1005无法创建表格 '数据库#SQL-498_8797' (错误:150)
[PDOException]
SQLSTATE [HY000]:常规错误:1005无法创建表格 '数据库#SQL-498_8797' (错误:150)
这是我得到的转储sql
CREATE TABLE prohibited_language_google(country_id VARCHAR(2)NOT NULL,language_id VARCHAR(20)NOT NULL,INDEX IDX_77B02D13F92F3E70 (country_id),INDEX IDX_77B02D1382F1BAF4(language_id),PRIMARY KEY(country_id,language_id))DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;更改表 prohibited_language_display ADD CONSTRAINT FK_77B02D13F92F3E70 FOREIGN KEY(country_id)REFERENCES r_country(id)ON DELETE CASCADE;改变 TABLE prohibited_language_google ADD CONSTRAINT FK_77B02D1382F1BAF4 FOREIGN KEY(language_id)REFERENCES r_language(id)ON DELETE CASCADE;
我尝试删除数据库并使用doctrine创建一个新的数据库,但这样就可以了,但我想做一个更新,否则我会丢失数据库中的所有数据。< / p>
有没有人可以帮助我?
答案 0 :(得分:1)
问题是Doctrine生成了一个脚本来创建带有collation utf_unicode_ci的表,我将其更改为utf8_general_ci 为了改变我必须将其添加到app / config.yml中的doctrineconfiguration
doctrine.dbal.default_table_options.collate: "utf8_general_ci"