首页 文章

Laravel中的mariaDB JSON支持

提问于
浏览
5

我'm trying to create a json database in XAMP, while using the phpmyAdmin it showed me that I'使用mariaDB,但在我的 xamp-control panel v3.2.2 中显示正在运行 mySQL on port 3306 . 我试图执行:'m using Laravel 5.4 framework to create the database, following is my migration which I'

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]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MariaDB服务器版本对应的手册,以便在第1行使用'json null,content json null,scripts json null,deleted_at timestamp null'附近使用正确的语法(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)

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

帮助我解决这个问题 .

2 回答

  • 4

    从版本10.2.7开始,MariaDB具有JSON数据类型的别名

    使用this package将MariaDB JSON添加到Laravel

  • 6

    请注意,1064抱怨数据类型为“json” . 这些(尚未)在MariaDB中实现 .

    你可以接近Dynamic Columns,它至少有一种方法可以将它们提取到JSON语法中 .

    另一件事(可能是你所指的)是CONNECT能够拥有JSON表类型 . (不是列类型 . )

    MySQL 5.7有一个名为 JSON 的数据类型,还有一堆操作这样的函数 .

相关问题