I love using spatie media library to handle different media objects in my Laravel applications. However, recently I discovered a strange issue while setting up one of my existing projects on my colleague’s new Windows machine. We were not using docker for that project so were likely to run into environment specific issues
The Error
After cloning the repo and installing composer dependencies, I ran the artisan command for migration. However I got an error like this:
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'json not null, `custom_properties` json not null, `responsive_images` json not n' at line 1 (SQL: create table `media` (`id` int unsigned not null auto_increment primary key, `model_type` varchar(191) not null, `model_id` bigint unsigned not null, `collection_name` varchar(191) not null, `name` varchar(191) not null, `file_name` varchar(191) not null, `mime_type` varchar(191) null, `disk` varchar(191) not null, `size` int unsigned not null, `manipulations` json not null, `custom_properties` json not null, `responsive_images` json not null, `order_column` int unsigned null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci’)
Additional error data:
Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'json not null, `custom_properties` json not null, `responsive_images` json not n' at line 1”)
I started looking for a reason for this error and found that Spatie uses ison type field for some columns. However this feature was not supported by the version of mariaDB we had.
I updated Spatie Media Library in a hope that it may resolve the issue but in didn’t.
Next I thought of downgrading the version of MariaDB or installing a newer version of MySQL. Both options would have taken considerable amount of time. So instead, I just edited the migration file called xxxx_create_media_table.php
and updated the following lines of code.
$table->json('manipulations');
$table->json('custom_properties');
$table->json('responsive_images');
All you have to do is replace json
with text
. Here is the final output.
$table->text('manipulations');
$table->text('custom_properties');
$table->text('responsive_images');
I ran the migration and it worked this time.
The workaround helped us to move further with out project but it was not an ideal solution. So just to make sure my original source code was intact, I removed the changes I made to migration file. This way, I was able to run the application on one particular machine with that issue. So it seemed fair enough. Time saved!
Leave a Reply