Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->integer('identifier')->unique();
$table->string('username')->unique();
$table->string('name');
$table->string('avatar');
$table->string('Trade')->nullable();
$table->decimal('funds')->default(0);
$table->enum('visibility', [1, 2, 3]);
$table->uuid('api_token');
$table->timestamps();
});
和
User::updateOrCreate([
'identifier' => 'dasdasd',
'username' => $user->nickname,
'name' => $user->name,
'avatar' => $user->avatar,
'visibility' => $user->visibility,
'api_token' => Uuid::generate()
]);
结果:sqlSTATE [HY000]:常规错误:1364字段’identifier’没有默认值(sql:插入用户(名称,Updated_at,created_at)值(Guilhermearaújo,2017-03-26 20:39:04 ,2017-03-26 20:39:04))
怎么了?
解决方法:
'identifier' => 12345,
由于使用的是updateOrCreate(),因此应将标识符添加到$fillable数组中:
protected $fillable = ['identifier', ....];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。