Steve
Steve

Reputation: 4908

How do I leave a field unspecified during a PDO INSERT?

I have a MYSQL table for users that holds a field for phone,

image

If I do an insert (using PDO) and don't specify phone, I get the error:

Failed to run query: SQLSTATE[HY000]: General error: 1364 Field 'phone' doesn't have a default value

I've tried changing the Default with phpMyAdmin to NULL, but hpMyAdmin won't take that as a default. If I delete the phone field it just goes on to report the same error for the next field I'm not specifying, streetAddress.

So how can I set this up so MySQL will not complain if I put in a new record without specifying certain fields?

Upvotes: 0

Views: 144

Answers (1)

SilverSnake
SilverSnake

Reputation: 572

I assume the second to last column in your screenshot is the "allow NULL" one. Since it's set to no for phone, you aren't allowed to set the default value to NULL. If you switch that to yes first, it should work fine to set the default value to NULL after that. Compare with ct_password which has default value NULL.

That should sort out your issues I believe.

Upvotes: 1

Related Questions