mysql - 在 Laravel 中迁移

标签 mysql laravel

我在迁移我的表时遇到错误。 错误说

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, start_date date not null, end_date date not null, status enum('' at line 1 (SQL: create table modules (id int unsigned not null auto_increment primary key, title varchar(191) not null, description text not null, image blob null, resources json null, start_date date not null, end_date date not null, status enum('pending', 'start', 'completed') not null default 'pending', user_id int not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

我的表有以下值:

public function up()
    {
        Schema::create('modules', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->text('description');
            $table->binary('image')->nullable();
            $table->json('resources')->nullable();
            $table->date('start_date');
            $table->date('end_date');
           $table->ENUM('status',['pending','start','completed'])->default('pending');
            $table->integer('user_id');
            $table->timestamps();
        });
    }

这是我的模型代码:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

    class modules extends Model
    {
        protected $fillable = [
            'title', 'description','image','resources', 'start_date','end_date','status','user_id',
        ];
    }

谁能解决这个问题??

最佳答案

从 Laravel 开始,$table->json() 方法将尝试在数据库中创建一个实际的 JSON 字段。然而,直到MySQL 5.7.8,JSON字段才被添加到MySQL中。

因此,如果您使用 5.7.8 之前的 MySQL 版本,您只需将其创建为文本字段即可

MariaDB 新版本支持 JSON。 (Alpha 版本。Maria 不推荐用于生产服务器。仅用于测试。)

MariaDB 10.1 不支持 JSON

关于mysql - 在 Laravel 中迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53813145/

相关文章:

mysql动态sql

mysql - MySQL UPDATE 语法有什么问题?

mysql - 如果列为空,如何停止使用 CONCAT_WS 添加逗号

javascript - 无法访问数据。对象在另一个对象中?

php - 如何查询一对多关系

php - 基于表单中的onChange事件动态构建AJAX请求

php - updateOrCreate 数组中的多个属性( Eloquent )

php - 在 Laravel 中发布多个具有相同名称的字段

php - Laravel 助手接口(interface)

laravel - 在 Controller 中使用 foreach 时出现语法错误