-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use correct charset/collation from column/table defaults when creating relationships #9636
Conversation
6ae9e92
to
90c27be
Compare
da30236
to
5b527ec
Compare
@greg0ire Ok, the PR is green again 🎉 |
cdb8a92
to
a822fb2
Compare
Thanks @ruudk ! |
* 2.12.x: Leverage generic persistence event classes (doctrine#9633) Fix static analysis for Persistence 2.5 (doctrine#9648) Improve exception message (doctrine#9646) Deprecate console helper (doctrine#9641) Use charset/collation from column or table default when creating relations (doctrine#9636) Support Enum IDs and search by Enum fields (doctrine#9629) Fix composer install in contributing readme
@greg0ire @derrabus The problem is as follows: For example, this SQL was produced: CREATE TABLE table_name (
// ..
user_id INT CHARACTER SET utf8 NOT NULL COLLATE `utf8_unicode_ci`
// ..
) resulting in this error:
|
I think the solution can be simple, never include CREATE TABLE table_name (
// ..
user_id INT NOT NULL COLLATE `utf8_unicode_ci`,
string_user_id VARCHAR(255) NOT NULL COLLATE `utf8_unicode_ci`,
// ..
) |
The fix introduced in doctrine#9636 now breaks when working with integer relations. Putting `charset` and `collation` on a text join column works fine, but when the column is an integer, MySQL won't accept it: ```sql CREATE TABLE table_name ( // .. user_id INT CHARACTER SET utf8 NOT NULL COLLATE `utf8_unicode_ci` // .. ) ``` produces this error: ``` Query 1 ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHARACTER SET utf8 NOT NULL COLLATE `utf8_unicode_ci`, type VARCHAR(255) NOT NUL' at line 1 ``` Luckily the solution is simple. The charset is not needed as MySQL automatically derives that from the `collation` when specified. It's also clever enough to ignore `collation` when the type is an integer. Therefore the following works fine: ```sql CREATE TABLE table_name ( // .. user_id INT NOT NULL COLLATE `utf8_unicode_ci`, string_user_id VARCHAR(255) NOT NULL COLLATE `utf8_unicode_ci`, // .. ) ```
This should fix the problem: #9652 |
…ing relations (doctrine#9636)" This reverts commit 03f4468. The inferring process seems fragile and MySQL-specific. The ORM might not be the correct place to fix this issue (if it needs to be fixed at all).
Revert "Use charset/collation from column or table default when creatng relations (#9636)"
* 2.12.x: Indicate support for doctrine/persistence 3 (doctrine#9656) Fix tests for enum ID hydration (doctrine#9658) Revert "Use charset/collation from column or table default when creating relations (doctrine#9636)" Fix test file/class names (doctrine#9649)
* 2.12.x: Indicate support for doctrine/persistence 3 (doctrine#9656) Fix tests for enum ID hydration (doctrine#9658) Revert "Use charset/collation from column or table default when creating relations (doctrine#9636)" Fix test file/class names (doctrine#9649)
* 2.12.x: Indicate support for doctrine/persistence 3 (doctrine#9656) Fix tests for enum ID hydration (doctrine#9658) Revert "Use charset/collation from column or table default when creating relations (doctrine#9636)" Fix test file/class names (doctrine#9649)
* 2.12.x: Indicate support for doctrine/persistence 3 (doctrine#9656) Fix tests for enum ID hydration (doctrine#9658) Revert "Use charset/collation from column or table default when creating relations (doctrine#9636)" Fix test file/class names (doctrine#9649)
Fixes #6823
When you have entities and columns with different charset/collation the SchemaTool should be smart and use the correct charset/collection for the column that references the other table.
In the tests I created the following entities:
👉 As you can see, the
group_id
column uses the charset/collation from thegroup
table default.For the
status_id
, it uses the charset/collation from theid
column because that was set explicitly.👉 As you can see, the
id
column ofgroup
uses the table default.👉 As you can see, the
id
column ofstatus
is different than the table default.When I disable the fix in SchemaTool, the following errors would be produced: