While running php artisan migrate, I got the following error
[Doctrine\DBAL\DBALException]
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.
How to resolve this issue.
Code:
public function up() {
Schema::table('blogs', function (Blueprint $table) {
$table->string('wordpress_id')->nullable();
$table->string('google_blog_id')->nullable()->change();
});
}
It is a known issue as stated in Laravel 5.1 documentation.
It happens when you have a
enum
column in your database table. Whether you are trying to rename another column, or change another column tonullable
, this bug will appear. It's an issue withDoctrine\DBAL
.An easy fix for this is to just add this constructor method in your database migration file.
This will map all the
ENUM
columns toVARCHAR()
, and the column will accept any string.Credit to @Gmatkowski's answer at https://stackoverflow.com/a/32860409/1193201
The official Laravel 5.1 documentation states:
It doesn't matter if you're trying to change another column, if the table contains a
enum
anywhere it won't work. It's a Doctrine DBAL issue.As a workaround you could either drop the column and add a new one (column data will be lost):
or use a DB statement:
Source: https://github.com/laravel/framework/issues/1186
A real dirty solution, that gets the job done none the less would be to
by ading these lines just above line 113
Beware that updating vendor files directly is not advisable because in the event the vonder chooses to update the plugin, you changes could be overwritten
I get rid of this problem by creating a new Migration Class and making my migrations extending from it. There are multiple ways to make more "standard" but this is just a very simple case which works perfectly for me.
Then as explained before just extend your migration from it