Laravel db migration - renameColumn error - Unknown database type enum requested

前端 未结 8 871
暗喜
暗喜 2020-12-10 11:53

I am using Laravel 4.2. I have the following library loaded in my composer.json

\"doctrine/dbal\": \"2.4.*\",

I c

8条回答
  •  没有蜡笔的小新
    2020-12-10 12:01

    I met this problem in Laravel version 5.1.19 (LTS). This is actual for earlier versions too. I wanted to inform you as I resolved the issue base on previous comments.

    First of all, I tried next code in my migration file:

    $table->renameColumn('column_name');
    

    But after command php artisan migrate, I got next error:

    [Symfony\Component\Debug\Exception\FatalErrorException] Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found

    As you know DBAL was removed from the laravel core and we need add it to the composer.json.(For example:"require": {"doctrine/dbal": "2.5.1"}). I set DBAL as required and tried again to do migrate command but got next error:

    [Doctrine\DBAL\DBALException]
    Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.

    Then I tried next raw sql in my migration file: For up():

    DB::statement("ALTER TABLE `table_name` CHANGE `old_column_name` `new_column_name` ENUM('first value', 'second_value', ...) DEFAULT 'first_value' AFTER `some_field`");
    

    For down():

    DB::statement("ALTER TABLE `table_name` CHANGE `new_column_name` `old_column_name` ENUM('first value', 'second_value', ...) DEFAULT 'first_value' AFTER `some_field`");
    

    and it works.

    P.S. For renaming other fields in the table which contains an enum field we should use same schema with raw sql as was written in previous comments.

提交回复
热议问题