gpt4 book ai didi

php - 一般错误 : 1364 Field 'identifier' doesn't have a default value

转载 作者:可可西里 更新时间:2023-11-01 08:09:46 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com