我在迁移我的表时遇到错误。 错误说
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 tablemodules
(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/