It's just now that I noticed from the video tutorial that Laravel has this foreignId
-constrained
. So I try change my code from method.1 to method.2, the table migrated but when I try to db:seed
, the default value is not working (it returns an error below).
(Method.1)
$table->unsignedBigInteger('status_id')->default(1);
$table->foreign('status_id')
->references('id')
->on('user_statuses');
(Method.2)
$table->foreignId('status_id')->constrained('user_statuses')->default(1);
(Error returned using method.2)
SQLSTATE[HY000]: General error: 1364 Field 'status_id' doesn't have a default value (SQL: insert into
users
(username
,password
) values (admin, $2y$10$S ZUIglBQG/HhS/18zn41GOcH8f.hZaNewmyoGJBfDQchfC6OWdx26))