Mat*_* K. 8 mysql doctrine symfony doctrine-orm doctrine-migrations
当我运行时php bin/console doctrine:migrations:diff,我总是得到以下新生成的迁移:
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20220221174647 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
}
public function down(Schema $schema): void
{
// example with one table but migration generates this for all varchar column, in all tables
$this->addSql('ALTER TABLE address CHANGE company_name company_name VARCHAR(100) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE address_line1 address_line1 VARCHAR(100) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE zip_code zip_code VARCHAR(10) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE city city VARCHAR(50) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE country country VARCHAR(50) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE tax_identifier tax_identifier VARCHAR(255) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`');
}
}
Run Code Online (Sandbox Code Playgroud)
我的SHOW CREATE TABLE address
CREATE TABLE `address` (
`id` int NOT NULL AUTO_INCREMENT,
`company_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`address_line1` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`zip_code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`country` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`updated_at` datetime NOT NULL,
`created_at` datetime NOT NULL,
`tax_identifier` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
Run Code Online (Sandbox Code Playgroud)
SHOW VARIABLES LIKE 'character\_set\_%';结果:
| 变量名 | 价值 |
|---|---|
| 字符集客户端 | utf8mb4 |
| 字符集连接 | utf8mb4 |
| 字符集数据库 | utf8mb4 |
| 字符集文件系统 | 二进制 |
| 字符集结果 | utf8mb3 |
| 字符集服务器 | utf8mb4 |
| 字符集系统 | utf8mb3 |
结果SELECT @@character_set_database, @@collation_database;:
@@character_set_database: utf8mb4
@@collation_database: utf8mb4_unicode_ci
Run Code Online (Sandbox Code Playgroud)
我还将学说配置设置为:
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20220221174647 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
}
public function down(Schema $schema): void
{
// example with one table but migration generates this for all varchar column, in all tables
$this->addSql('ALTER TABLE address CHANGE company_name company_name VARCHAR(100) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE address_line1 address_line1 VARCHAR(100) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE zip_code zip_code VARCHAR(10) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE city city VARCHAR(50) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE country country VARCHAR(50) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE tax_identifier tax_identifier VARCHAR(255) DEFAULT NULL COLLATE `utf8mb4_unicode_ci`');
}
}
Run Code Online (Sandbox Code Playgroud)
这肯定是一个错误。我正在使用 Symfony 编写一个应用程序,在版本 2022.02.08 和 2022.02.09 的迁移之间开始发生同样的事情。
编辑:检查我的composer.json,在这两个版本之间,我将 PHP 从 8.0 更新到 8.1,将 Symfony 从 5.4.* 更新到 6.0.*。我仍然相信这是 Symfony 上的一个错误......
| 归档时间: |
|
| 查看次数: |
1461 次 |
| 最近记录: |