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