Search code examples
mysqlsymfonycharacter-encodingdoctrinesymfony-3.3

Cant create Foreign Key between 2 tables with different CHARSET


Foreign keys across different Charset does not work

I'm Using Symfony with Doctrine to make a new project. But the old tables have the default Charset different to UTF-8. My new tables have UTF8 Charset. Resuming.. I have one table with DEFAULT CHARSET = latin1 and a new table in UTF-8.

UTF8 table has a relationship with latin1 table. But i get the next error:

MySQL: Error 1005; Can't create table (errno: 150)

There is some way to make a foreign key between tables with different CHARSET ? OR, Can i do it with ORM level?


Solution

  • There is some way to make a foreign key between tables with different CHARSET ?

    On MySQL level no there isn't.

    Corresponding columns in the foreign key and the referenced key must have similar data types. The size and sign of integer types must be the same. The length of string types need not be the same. For nonbinary (character) string columns, the character set and collation must be the same

    Source: http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html