# Mysql prob?



## binsky3333 (Aug 12, 2008)

Ok whenever i try and create this table:
CREATE TABLE users (
id int(10) DEFAULT '0' NOT NULL auto_increment, 
username varchar(40),
password varchar(50), 
regdate varchar(20),
email varchar(100),
website varchar(150),
location varchar(150),
show_email int(2) DEFAULT '0',
last_login varchar(20),
PRIMARY KEY(id))

I always get an error saying:
MySQL said:  

#1067 - Invalid default value for 'id' 

I have no clue what that means, is there something wrong with my code?


----------



## ZenZimZaliben (Aug 12, 2008)

Easy enough...You're running a later version of MYSQL. Anything past 5.x you no longer need to set a default value for auto_increment. So just remove the default part where ever you have specified auto_increment.

You can alter your sql file as well to fix this. Open the sql file in your editor (vi)...and type in minus the double quote.

"s/\(.*\)DEFAULT '0'\(.*\)auto_increment/\1\2auto_increment/). " crud it made a smiley.

" : (s/\(.*\)DEFAULT '0'\(.*\)auto_increment/\1\2auto_increment/). " without the first space


----------



## Deleted member 3 (Aug 12, 2008)

Auto increment doesn't have a default. ie you can't default 0 since it's auto increment, it picks the number for you.


----------



## ZenZimZaliben (Aug 12, 2008)

Hmmm I think you just said what I did in 20 less words. Much better, good job.

Versions older then 5.x did use a default value for auto_increment. No need for it anymore, but check your version of mysql.


----------



## blTb (Aug 21, 2008)

```
id int(10) DEFAULT '0' NOT NULL auto_increment,
```
There is one more mistake:
*id* is not *NULL*, but you're giving a default value = *0*!


----------



## W1zzard (Aug 21, 2008)

install phpmyadmin to make such administrative tasks much easier


----------

