dbal: A wrong charset migration is generated everytime with doctrine/dbal 3.3.1
Bug Report
There is a regression caused by doctrine/dbal 3.3.1 in migrations generation.
Q | A |
---|---|
Version | 3.3.1 |
Summary
Using doctrine/migrations-bundle:3.2.1
:
- With
doctrine/dbal
3.2.0 to 3.3.0 (I tested them all). The commanddoctrine:migrations:diff
produces no migration if there is no change in the schema. - With
doctrine/dbal
3.3.1 . The commanddoctrine:migrations:diff
produces an emptyup()
migration and a wrongdown()
migration even if there is no change in the schema (and produces it everytime it’s ran).
How to reproduce
Not sure about it. I’m using MariaDB 10.5.12, but another user had this issue and reportedly uses MySQL 5.7. At first I posted in #3391 thinking it was maybe older than that.
In Symfony, Doctrine is configured such as:
doctrine:
dbal:
url: '%database_url%'
server_version: 'mariadb-10.5.12'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
And the wrong down migration produced is full of charset changes:
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE address CHANGE street street VARCHAR(255) NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE city city VARCHAR(255) NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE post_code post_code VARCHAR(255) NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE country country ENUM(\'fr\') NOT NULL COLLATE `utf8mb4_unicode_ci` COMMENT \'(82a9e4d26595c87ab6e442391d8c5bba)(DC2Type:countryenum)\', CHANGE first_name first_name VARCHAR(255) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE last_name last_name VARCHAR(255) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`');
$this->addSql('ALTER TABLE api_key CHANGE token token VARCHAR(255) NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE role role VARCHAR(255) NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE type type VARCHAR(255) NOT NULL COLLATE `utf8mb4_unicode_ci`');
$this->addSql('ALTER TABLE blog_article CHANGE title title VARCHAR(255) NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE excerpt excerpt LONGTEXT NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE external_link external_link VARCHAR(255) NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE slug slug VARCHAR(255) NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE image_filename image_filename VARCHAR(255) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`');
...
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 25 (7 by maintainers)
@Pixelshaped @morozov @natewiebe13 I always have the same problem with doctrine/dbal 3.3.2 Wrong charset migrations are generated at each call to
php bin/console doctrine:migrations:diff
The bug is gone for me in 3.3.4. @greg0ire pushed a new release yesterday. Check it before opening a new issue.
OK, I’m on it.
@Pixelshaped could be fixed by https://github.com/doctrine/dbal/pull/5326
Hi,
I have this issue on 3.3.2 too.
@morozov let’s do a release?
Thanks for reporting a solution, unfortunately all my columns are standard
utf8mb4_unicode_ci
and this bug still happens. I’ll create another issue if not exists.If you are still seeing the issue (like I was), also check the charset matches the collation. I have collation set to utf8mb4_unicode_ci by default, and some DB fields were set to ascii_general_ci.
Hinted by https://github.com/doctrine/dbal/pull/5224/files I added this to AbstractPlatform::columnsEqual:
Then ran the schema update command and saw:
Which I could fix by specifying the charset as well on the property’s annotation:
Simply specifying the collation there was not enough to fix it.
Hopefully this helps someone else.
I created a minimal project here: https://github.com/natewiebe13/doctrine-dbal-bug
Since it might be dependent on which database/env setup, I’ve included a docker environment to hopefully help with replication.