没有不值得去解决的问题,也没有不值得去学习的技术!

Updating Column Attributes in Laravel 6 Migrations Triggers Doctrine\DBAL\Exception: Unknown Database Type Enum Requested, Doctrine\DBAL\Platforms\MySQL57Platform May Not Support It

Doctrine\DBAL\Exception : Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.

1. Doctrine\DBAL\Exception : Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it. As shown in Figure 1

Doctrine\DBAL\Exception  : Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.
Figure 1
Plaintext

PS E:\wwwroot\object> php artisan module:migrate ThemeStoreDB
Migrating: 2022_12_08_173303_alter_theme_store_theme_version_semantic_on_theme_installation_version_preset_table

   Doctrine\DBAL\Exception  : Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.

  at E:\wwwroot\object\vendor\doctrine\dbal\lib\Doctrine\DBAL\Platforms\AbstractPlatform.php:454
    450|
    451|         $dbType = strtolower($dbType);
    452|
    453|         if (! isset($this->doctrineTypeMapping[$dbType])) {
  > 454|             throw new Exception(
    455|                 'Unknown database type ' . $dbType . ' requested, ' . static::class . ' may not support it.'
    456|             );
    457|         }
    458|

  Exception trace:

  1   Doctrine\DBAL\Platforms\AbstractPlatform::getDoctrineTypeMapping("enum")
      E:\wwwroot\object\vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\MySqlSchemaManager.php:134

  2   Doctrine\DBAL\Schema\MySqlSchemaManager::_getPortableTableColumnDefinition()
      E:\wwwroot\object\vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\AbstractSchemaManager.php:820

  Please use the argument -v to see more details.

2. Checking the migration file, there is no enum among the field types being updated.

PHP

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('theme_installation_version_preset', function (Blueprint $table) {
            $table->string('theme_store_theme_version_semantic', 64)->comment('主题商店的主题版本的语义化')->change();
        });
    }

3. Finally, I determined the cause: other fields in the table involved in this migration likely use the enum type. As shown in Figure 2

Finally, I determined the cause: other fields in the table involved in this migration likely use the enum type
Figure 2

4. Referring to https://www.shuijingwanwq.com/2022/06/02/6483/ , I used DB::statement. The migration executed successfully. As shown in Figure 3

Referring to https://www.shuijingwanwq.com/2022/06/02/6483/ , I used DB::statement. The migration executed successfully
Figure 3
PHP

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $fullTableName = DB::connection()->getTablePrefix() . 'theme_installation_version_preset';
        DB::statement("ALTER TABLE $fullTableName modify theme_store_theme_version_semantic varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '主题商店的主题版本的语义化'");
    }

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系