5 months ago

Insert a row when no columns are defined

Posted 5 months ago by Mego

I have a table user_profiles, which contains user_profile_id, user_id, birthdate, profile_image... 10 columns alltogether. In one place of my application, I need to create a row for new user in this table, but with only "user_id" column, I don't want to define the others columns and I would like to let them blank. Howeve, I am getting this error:

SQLSTATE[HY000]: General error: 1364 Field 'profile_image' doesn't have a default value (SQL: insert into user_profiles (user_id) values (27))

I need only to create a row with user_id (and primary key user_profile_id of course), and let the others column blank. How can I do that and remove this error? I don't thnik, it's good practise to write down each column and set it to null

My code looks like:

DB::table('user_profiles')->insert( [ 'user_id' => $newUserId->id, ] );

I tried to google and I google something about strict trans table, or something like this... however I try to turn it off and it was succesfull, however the error is still there. Database is MySQL 5.6 with MyIsam engine

Thanks for help

Please sign in or create an account to participate in this conversation.