dsjj15012 2016-07-28 13:10
浏览 57
已采纳

doctrine manyToMany SQLSTATE [HY000]:常规错误:1005无法创建表(错误号:150)

I have an issue with

/**
 * @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;
...
}

i'm trying to do a ManyToMany relation with doctrine but when i do an update it fires an error

[Doctrine\DBAL\Exception\DriverException]
An exception occurred while executing 'ALTER TABLE prohibited_language_display ADD CONSTRAINT FK_77B02D13F92F3E70 FOREIGN KEY (country_id) REFERENCES r_country (id) ON DELETE CASCADE':
SQLSTATE[HY000]: General error: 1005 Can't create table 'database.#sql-498_8797' (errno: 150)

                                                                                                         [Doctrine\DBAL\Driver\PDOException]                                   

SQLSTATE[HY000]: General error: 1005 Can't create table 'database.#sql-498_8797' (errno: 150)

                                                                                                         [PDOException]                                                        

SQLSTATE[HY000]: General error: 1005 Can't create table 'database.#sql-498_8797' (errno: 150)

this is th dump sql i get

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; ALTER TABLE prohibited_language_display ADD CONSTRAINT FK_77B02D13F92F3E70 FOREIGN KEY (country_id) REFERENCES r_country (id) ON DELETE CASCADE; ALTER TABLE prohibited_language_google ADD CONSTRAINT FK_77B02D1382F1BAF4 FOREIGN KEY (language_id) REFERENCES r_language (id) ON DELETE CASCADE;

i've tryed de drop the database and create a new one with doctrine with and it's ok that way, but i want to just do an update otherwise i ill lose all data in my database.

Is there any one who can help me?

  • 写回答

1条回答 默认 最新

  • dongtun1872 2016-07-28 14:21
    关注

    the problem was that Doctrine generates a script to create the table with collation utf_unicode_ci, i changed it to be utf8_general_ci in order to change that i had to add this to my doctrineconfiguration in app/config.yml

    doctrine.dbal.default_table_options.collate: "utf8_general_ci"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用