Reputation:
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();
});
and
User::updateOrCreate([
'identifier' => 'dasdasd',
'username' => $user->nickname,
'name' => $user->name,
'avatar' => $user->avatar,
'visibility' => $user->visibility,
'api_token' => Uuid::generate()
]);
Results: SQLSTATE[HY000]: General error: 1364 Field 'identifier' doesn't have a default value (SQL: insert into users
(name
, updated_at
, created_at
) values (Guilherme Araújo, 2017-03-26 20:39:04, 2017-03-26 20:39:04))
What is wrong?
Upvotes: 3
Views: 3409
Reputation: 88
If your variable identifier is user fillable, then it must be filled with an integer value.
Upvotes: 0
Reputation: 163748
You should generate an unique integer for the identifier
field:
'identifier' => 12345,
And since you're using updateOrCreate()
you should add identifier
to the $fillable
array:
protected $fillable = ['identifier', ....];
Upvotes: 3