在迁移中尝试 table->json('options') 时出错

getting error when trying to table->json('options') in migration

我的迁移看起来像这样

    Schema::create('reports', function (Blueprint $table) {
        $table->bigincrements('id');
        $table->json('options');
    });

我收到这个错误:

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) default character set utf8 collate utf8_unicode_ci' at line 1

如果我删除 $table->json('options'); 则没有错误。

Laravel 5.3 文档提到了这个 https://laravel.com/docs/5.3/migrations 所以我没有做错任何事情,知道为什么我会收到这个错误吗?

我正在使用支持 json 类型的 MariaDB 10.1.16 版。

我四处寻找解决方案。

假设您的 MariaDB 版本是正确的,它确实不支持它。我确实在 laravel 回购上找到了一个已关闭的 GitHub 问题,this comment 指出

MariaDB 10.2 supported JSON. (Alpha version. Not recommended by Maria to production server. 
Only testing.)

MariaDB 10.1 do not support JSON (

所以我建议您的 MariaDB 版本有误,或者实际上不支持 JSON 列。

我相信你的数据库不支持JSON

您可以创建文本并将 json 文件保存为字符串,然后在从数据库中检索时解析它们。

MariaDB 以两种方式支持 JSON,但都不是 "datatype"。该错误未被 Laravel ($table->json(...)) 捕获,因为其他数据库确实具有 JSON 数据类型 .

  • Json table type (10.0.16) 谈论如何使用 "Connect" 将 Json 编码的文件挂接到 MariaDB。
  • Dynamic Columns (10.0.1) 在幕后使用 BLOB,加上函数 COLUMN_JSON 将列解释为 Json.

MariaDB 是否选择 Oracle 5.7's JSON datatype (5.7.8) 是一个推测问题。