在迁移表时,我收到了一个错误。错误说
SQLSTATE42000:语法错误或访问冲突: 1064您的SQL语法中有一个错误;检查与您的MariaDB服务器版本对应的手册,以获得正确的语法,以使用接近'json,
start_datedate not null,end_datedate not null,statusenum(第1行: create tablemodules(idint unsigned not null auto_increment主键,titlevarchar(191) null,descriptiontext null,imageblob null,resourcesjson null,start_date日期null,end_date日期null,d12enum(“未决”,'start‘),‘完成’)非空默认值‘未决’,user_id int不为空,created_at时间戳为空,updated_at时间戳为空)默认字符集utf8mb4排序规则'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',
];
}有人能找到解决办法吗??
发布于 2018-12-17 10:30:59
从Laravel开始,$table->json()方法将尝试在数据库中创建一个实际的JSON字段。但是,直到MySQL MySQL 5.7.8才将JSON字段添加到JSON中。
因此,如果在使用MySQL之前使用5.7.8版本,则只需将其创建为文本字段
MariaDB新版本支持JSON。(阿尔法版本。玛丽亚不推荐生产服务器。(只有测试。)
MariaDB 10.1不支持JSON
发布于 2018-12-17 10:32:04
早期版本的maria db不支持json字段类型,请参阅链接https://mariadb.com/resources/blog/json-with-mariadb-10-2/。
请验证您的mariadb版本。
发布于 2018-12-17 11:50:09
可能会添加$casts类属性来解决问题。
class modules extends Model
{
protected $casts = [
'resources' => 'array',
];
}这里可能对你有帮助。
https://stackoverflow.com/questions/53813145
复制相似问题