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

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

I have an issue with

  1. /**
  2. * @package Entity
  3. * @ORM\Entity
  4. * @ORM\Table(name="r_country")
  5. */
  6. class RCountry {
  7. /**
  8. * @ORM\Column(type="string", length=2)
  9. * @ORM\Id
  10. */
  11. protected $id;
  12. ...
  13. /**
  14. *
  15. * @ORM\ManyToMany(targetEntity="RLanguage")
  16. * @ORM\JoinTable(name="prohibited_language_display",
  17. * joinColumns={@ORM\JoinColumn(name="country_id", referencedColumnName="id", onDelete="CASCADE")},
  18. * inverseJoinColumns={@ORM\JoinColumn(name="language_id", referencedColumnName="id", onDelete="CASCADE")}
  19. * )
  20. *
  21. */
  22. protected $prohibitedLanguageDisplay;
  23. ...
  24. }
  25. /**
  26. * @package Entity
  27. * @ORM\Entity
  28. * @ORM\Table(name="r_language")
  29. */
  30. class RLanguage
  31. {
  32. /**
  33. * @ORM\Column(type="string", length=20)
  34. * @ORM\Id
  35. *
  36. */
  37. protected $id;
  38. ...
  39. }

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 06: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"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部