Laravel 中的 mariaDB JSON 支持

2024-05-11php开发问题
2

本文介绍了Laravel 中的 mariaDB JSON 支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

I'm trying to create a json database in XAMP, while using the phpmyAdmin it showed me that I'm using mariaDB but in my xamp-control panel v3.2.2 it shows running mySQL on port 3306. I'm using Laravel 5.4 framework to create the database, following is my migration which I'm trying to execute:

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();
});

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

Now while executing this I'm getting following error:

SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;查看与您的 MariaDB 服务器版本相对应的手册,了解在 'json null, content json null, scripts json null, deleted_at 第 1 行的时间戳 null'(SQL:创建表 pages (id int unsigned not null auto_increment 主键,title varchar(191) notnull, 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) 默认字符集 utf8mb4 collate utf8mb4_unicode_ci)

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

Even if I keep not null it throws the same error. I want to have json formatted data, I checked the supported version and as per the documentation json format support started from the version MariaDB 10.0.16. and I'm using 10.1.21-MariaDB

帮我解决这个问题.

推荐答案

MariaDB 10.2.7 版本开始;JSON 数据类型是 LONGTEXT 的别名.

Since MariaDB version 10.2.7; theJSON data-type is an alias for LONGTEXT.

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

If you are having issues with the JSON data-type in MariaDB, simply just change it to LONGTEXT. ;-)

或者使用 这个包

这篇关于Laravel 中的 mariaDB JSON 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17