Change nullabe() to nullable() and try it again :) you shouldn't need default(null) - if the field is nullable it will just be null if nothing is passed to it
Default value of null for integer turns to 0 during seeding
Hi,
I ran across an issue where I was trying to change my default value of 0 to null for my price field.
//before
$table->smallInteger('price')->unsigned()->nullabe()->default(0);
//after
$table->smallInteger('price')->unsigned()->nullabe()->default(NULL);
However, I kept running into errors during seeding.
SQLSTATE[HY000]: General error: 1364 Field 'price' doesn't have a default value (SQL: insert into `listings` (`title`, `author`, `isbn`, `isbn13`, `condition`, `additional_information`, `user_id`, `availability`, `upload_date`) values (Dolores est., Arnoldo Haag PhD, 4411084406, 9795024988144, 4, At velit., 1, Y, 2018-05-21 04:52:22))
I found online a solution to mark strict=> for mysql mode in my config/database file and that fixed my error and allowed me to continue however, the default value during my seeding continued to default to 0 even though I ran the migrations again and seeded.
Does anyone know if it is not a good practice to try and set null default values for integer fields because it works perfectly for me to set default null values for my varchar fields? Any guidance on how to set the integer field to null for default would be appreciated. It's not an absolute requirement for my spec but I think it makes more sense if a listing is not for sale, for it have a null price as opposed to have a $0 price.
Thanks.
Please or to participate in this conversation.