I saw similar questions but non of them work for me. This is the Transition
model
class Transition extends Model
{
protected $fillable = ['origin_x', 'origin_y', 'destination_x', 'destination_y', 'freight_id', 'status', 'receiver_name', 'receiver_mobile', 'receiver_address'];
protected $table = 'freight_transitions';
}
and this is the insertion code
$transition = Transition::create([
'origin_x' => $redis['origin_x'],
'origin_y' => $redis['origin_y'],
'destination_x' => $redis['destination_x'],
'destination_y' => $redis['destination_y'],
'freight_id' => $freight->id,
'status' => 2,
'receiver_name' => $redis['receiver_name'],
'receiver_mobile' => $redis['receiver_mobile'],
'receiver_address' => $redis['receiver_address']
]);
I am sure the array of $redis` has value. But this is the error
General error: 1364 Field 'origin_x' doesn't have a default value (SQL: insert into
freight_transitions
(updated_at
,created_at
) values (2019-11-02 16:42:58, 2019-11-02 16:42:58))
From what I see, the Laravel does not try to insert the origin_x
and other fields in to the DB. it only inserts the created_at
and updated_at
. I have a similar model called Freight
, in a few lines above this code, I insert records in the same way with no error. But I don't know why it only inserts the created_at
and updated_at
.
I also tried
$transition = new Transition([....]);//array of above data
$transition->save();
It also generates the same error.
Thanks in advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire