php - Laravel 中的 mariaDB JSON 支持

标签 php json laravel mariadb laravel-5.4

我正在尝试在 XAMP 中创建一个 json 数据库,同时使用 phpmyAdmin 它告诉我我正在使用 mariaDB 但在我的 xamp-control panel v3.2.2 中它显示正在运行 mySQL 在端口 3306 上。我正在使用 Laravel 5.4 框架创建数据库,以下是我尝试执行的迁移:

Schema::connection('newPortal')->create('pages', function (Blueprint $table){
    $table->increments('id');
    $table->string('title');
    $table->string('slug')->unique()->index();
    $table->json('styles')->nullable();
    $table->json('content')->nullable();
    $table->json('scripts')->nullable();
    $table->softDeletes();
    $table->timestamps();
});

现在执行此操作时出现以下错误:

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, content json null, scripts json null, deleted_at timestamp null' at line 1 (SQL: create table pages (id int unsigned not null auto_increment primary key, title varchar(191) not null, slug varchar(191) not null, styles json null, content json null, scripts json null, deleted_at timestamp null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)

即使我保持不为空,它也会抛出同样的错误。我想要 json 格式的数据,我检查了支持的版本,并根据文档 json 格式支持从版本 MariaDB 10.0.16. 开始,我正在使用 10.1.21-MariaDB

帮我解决这个问题。

最佳答案

MariaDB 版本 10.2.7; JSON 数据类型是 LONGTEXT 的别名。

如果您对 MariaDB 中的 JSON 数据类型有疑问,只需将其更改为 LONGTEXT。 ;-)

或者使用 this package 将 MariaDB JSON 添加到 Laravel

关于php - Laravel 中的 mariaDB JSON 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42425667/

相关文章:

php - PHP中静态成员的继承

ios - Mantle 2.0 无法为嵌套数组中的符号解析 JSON

python - Flask-restful:将复杂对象编码为 json

php - Laravel Eloquent 日期范围介于范围之间

php - 不可能在变量中返回简单函数

php - MYSQL 中带有否定的多个 Case 语句

javascript - 将 PHP $_POST 数组传递给 javascript/jQuery 以通过 ajax 发送回 PHP

javascript - 访问控制允许来源 : * is set but I still get Origin not allowed

php - Laravel 失败的作业到 Redis

javascript - Laravel - 使用 Ajax 从数据库中获取数据