SQLSTATE[HY000]: General error: 1005
By Stéphane.p on Friday, May 15 2009, 10:50 - Symfony - Permalink
SQLSTATE[HY000]: General error: 1005 Can't create table './ma_table/#sql-6d79_2523.frm' (errno: 150). Failing Query: ALTER TABLE table2 ADD FOREIGN KEY (table1) REFERENCES table1(id) ON DELETE SET NULL
Voilà une erreur qui m'est apparue plusieurs fois, assez embêtante lorsqu'on ne connait pas la solution.
Il s'agit bien d'une erreur MYSQL et pour la résoudre nous devrons donc passer par le/les schema.yml.
Exemple:
- config/
- doctrine/
- schema.yml
Table1:
columns:
name: { type: string(255), notblank: true }
Table2:
columns:
table_one_id: { type: integer(11) }
relations:
Table1: { local: table_one_id, foreign: id, onDelete: SET NULL }
Dans ce cas nous aurons l'erreur précédemment citée. La syntaxe est correcte, donc le problème ne devrait pas être.
Cependant, table_one_id étant un integer(11), et table1.id (généré automatiquement) étant un bigint(20), c'est ceci qui provoque cette erreur mysql.
Pour ma part, tous les integer étant des foreigns sont renseignés comme ceci:
table_one_id: { type: integer }
Vous aurez ce genre de problème lorsque vous téléchargerez des plugins symfony, je l'ai eu il me semble sur 'swDoctrineAssetsLibraryPlugin'.
Comments
Usally, I use this definition for id fileds :
myIdField : type: integer(11), primary: true, unsigned: true, autoincrement: true
The "unsigned" option preserves the size of the column for the database systems that support it (like mysql or postgresql)
Thanks for this tip =)
Plus généralement, il faut que la définition du champ "table_one_id" soit identique (en taille) à la définition du champ Table1.id.
Par exemple, dans le plugin sfDoctrineGuardPlugin, le champ ID de la table sfGuardUser est défini comme integer(4). Une référence à cette table devra donc aussi être un integer(4)...
Pas terrible finalement de devoir inspecter le schema.yml des plugins avant de pouvoir les utiliser réellement :-(
Merci beaucoup ! Vous m'avez bien aidé !
Merci beaucoup, après de longues heures de recherche ça marche enfin :)
mucho thanks
Do you want both quality and price, come here.
[url=http://www.toptoys2trade.com/animal... ]Animal Shaped Rubber Bands[/url],
[url=http://www.toptoys2trade.com/baby-c... ] Baby Carriers [/url],
[url=http://www.toptoys2trade.com/power-... ]power balance[/url],
[url=http://www.toptoys2trade.com/animal... ]Animal Rubber Bands[/url],
[url=http://www.toptoys2trade.com/mosqui... ]mosquito repellent wristband[/url]
[url=http://www.toptoys2trade.com/bakuga... ]new bakugan[/url],
[url=http://www.toptoys2trade.com/p90x-d... ]P90X DVDs[/url],