gpt4 book ai didi

php - Laravel 中的 mariaDB JSON 支持

转载 作者:可可西里 更新时间:2023-11-01 13:14:15 30 4
gpt4 key购买 nike

我正在尝试在 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com