Click to See Complete Forum and Search --> : default value error
asmith20002
01-16-2009, 12:22 PM
Hi,
Recently my mysql on my windows (locally) is giving error :
Column Example doesn't have a default value
It is when I'm trying to insert data to the mysql using php, but I don't enter all the columns for the whole row. I just try to insert the values in the columns I need, and leave other column. Before it wasn't like this, and it would insert the row and those columns i hadn't mentioned would be null or no value in them.
But recently it is giving me this error.
Is there a setting for that? How can I fix it?
skywalker2208
01-16-2009, 12:43 PM
Use alter table (http://dev.mysql.com/doc/refman/5.1/en/alter-table.html) and set the default value.
scragar
01-16-2009, 12:49 PM
mysql> describe tableName
mysql> alter table tableName modify Example FieldType(eg varchar(250) ) default '';
asmith20002
01-16-2009, 01:05 PM
Why in the past I didn't have such problem? I mean I never set a value for a column , just "not null" . I don't remember what changes have been made to my database.
My site database online, do not ave this problem, it works fine.
don't know what has happened locally.
any idea?
P.s What you are suggesting is, I alter my table. So I have to do that for everytable. I thought there's some kind of options in database to remove such error at all.
skywalker2208
01-16-2009, 01:13 PM
Yes you would have to do that to every table in the database. I am not aware of a setting. The problem might being happening because of a new version of MYSQL.
chazzy
01-16-2009, 01:25 PM
mysql's been like that since the 4.x releases, so it's nothing new. is it possible that you were setting a value from your scripts, but now aren't?
asmith20002
01-16-2009, 01:34 PM
I have been working on 4 different sites. and It was never like this.
Ok, Lets say it this way, Why the script which gives me this error, works fine online? The only difference I see is Online I'm running it on a Linux but locally it is on windows. Or maybe different versions of db online and local.
chazzy
01-16-2009, 04:41 PM
maybe in one case you marked the field to allow nulls and these you specifically marked not null? if you mark it not null it's either required or has a default value, just as the error states. like i said, it was functionality i believe was introduced in the 4.0.x or the 4.1.x so it could be that you were for a long while using very old versions to complete this with..