2016-09-23 57 views
-1
> JSON(「選項」)時收到錯誤

我的遷移看起來像這樣試圖向表中遷移

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所以我沒有做錯任何想法,爲什麼我得到這個錯誤?

我正在使用MariaDB版本10.1.16,它支持json類型。

回答

1

MariaDB支持兩種方式的JSON,它們都不是「數據類型」。該錯誤未被Laravel($table->json(...))捕獲,因爲其他數據庫確實有JSON 數據類型

  • Json table type(10.0.16)討論如何使用「連接」將Json編碼文件掛接到MariaDB中。
  • Dynamic Columns(10.0.1)採用BLOB,並加上函數COLUMN_JSON來解釋該列爲Json。

是否MariaDB拿起Oracle 5.7's JSON datatype(5.7.8)是一個猜測的問題。

1

我環顧四周尋找解決方案。

假設你的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列。

1

我相信你的數據庫不支持JSON

可以使文本和保存您的JSON文件作爲字符串,然後分析它們從數據庫中檢索時。