作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
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]: General error: 1364 Field 'identifier' doesn't have a default value (SQL: insert into users
(name
, updated_at
, created_at
) 值(Guilherme Araújo, 2017-03-26 20:39:04, 2017-03-26 20:39:04))
怎么了?
最佳答案
您应该为 identifier
字段生成一个唯一的整数:
'identifier' => 12345,
因为您正在使用 updateOrCreate()
,您应该将 identifier
添加到 $fillable
数组:
protected $fillable = ['identifier', ....];
关于php - 一般错误 : 1364 Field 'identifier' doesn't have a default value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43034320/
我是一名优秀的程序员,十分优秀!