framework: Use JSON data type in MariaDB got error
I use
$table->json('tags')->nullable();
in migrate,
The ‘mysql’ version is 10.1.14-MariaDB.
in MariaDB json colume called COLUMN_JSON(dyncol_blob)
https://mariadb.com/kb/en/mariadb/column_json/
[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 null) default character set utf8
collate utf8_unicode_ci’ at line 1 (SQL: create table pages (id int unsigned not null auto_increment primary k
ey, title varchar(255) null, tags json null) default character set utf8 collate utf8_unicode_ci)
[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 null) default character set utf8 collate utf8_unicode_ci’ at line 1
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 13
- Comments: 23 (11 by maintainers)
Commits related to this issue
- changed json column type to text because of no MariaDB support. Json column type is supported on MySql and Postgres as stated in https://laravel.com/docs/5.4/queries#json-where-clauses and https://git... — committed to OneOffTech/laravel-tus-upload by avvertix 7 years ago
- Update 2017_12_19_081247_create_products_table.php json no more supported by mariaDB https://github.com/laravel/framework/issues/13622 https://mariadb.com/kb/en/library/json-data-type/ — committed to poode/Demo by poode 6 years ago
MariaDB 10.2 supported JSON. (Alpha version. Not recommended by Maria to production server. Only testing.)
MariaDB 10.1 do not support JSON (
As per mariadb version 10.1.32 and lower it seems like mariadb does not support json data type I am still unsure if it is available in version 10.2.7+.
but here’s a simple workaround to get through this.
change json data type into text and then run your migration again.
thx it helps me
No one else running in this problem? I tried it on a fresh Forge Server and local with MariaDB (10.1.14 & 10.1.13). Laravel Framework version 5.2.32
Or is there an other clean way to shift with an existing project, migrations & database to MariaDB ?
I’m using laravel 8 and mariadb 10.5 and this is still happening
@shrutiakki json type not supported in MariaDB. MySQL 5.7.8 supports json type (for more information link ). Install MySQL 5.7.8+
Looks like MariaDB JSON data type support has been pushed back. In MariaDB’s Jira It is no longer set as fixed in 10.2. Best I can tell from looking at the dependant tasks, it is going to be at least 10.3
Trying this on 10.2 doesn’t work either…
This is a similar issue to having old MySQL versions. We made this change in 5.2. Either upgrade to a new version, or, just don’t use the json type in migrations. If you really want to use that in the migration, and want the old database version, you could stay on Laravel 5.1 LTS.