![]() |
|
|
#1 |
![]() |
Mysql prob?
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? |
|
|
|
|
|
#2 |
![]() Join Date: Mar 2005
Location: USA
Posts: 2,103 (0.70/day)
Thanks: 131
Thanked 517 Times in 383 Posts
|
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
__________________
i7 930 @ 4.2Ghz GIGABYTE x58 UD7 Kingston HyperX T1 Series 12GB GIGABYTE 7970 (1280/1800) OCZ Vertex 2 100GB SSD & VelociRaptor 300GB HEATWARE |
|
|
|
|
|
#3 |
|
Seņor Moderator
Join Date: May 2004
Location: Utrecht, Utrecht, The kingdom of the Netherlands
Posts: 8,498 (2.58/day)
Thanks: 41
Thanked 1,453 Times in 1,077 Posts
|
Auto increment doesn't have a default. ie you can't default 0 since it's auto increment, it picks the number for you.
|
|
|
|
|
|
#4 |
![]() Join Date: Mar 2005
Location: USA
Posts: 2,103 (0.70/day)
Thanks: 131
Thanked 517 Times in 383 Posts
|
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.
__________________
i7 930 @ 4.2Ghz GIGABYTE x58 UD7 Kingston HyperX T1 Series 12GB GIGABYTE 7970 (1280/1800) OCZ Vertex 2 100GB SSD & VelociRaptor 300GB HEATWARE |
|
|
|
|
|
#5 |
![]() Join Date: May 2008
Location: Littleton,CO
Posts: 248 (0.14/day)
Thanks: 33
Thanked 22 Times in 13 Posts
|
Code:
id int(10) DEFAULT '0' NOT NULL auto_increment, id is not NULL, but you're giving a default value = 0!
__________________
[FS/FT] bunch of interesting stuff |
|
|
|
|
|
#6 |
|
Benevolent Dictator
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 13,773 (4.18/day)
Thanks: 184
Thanked 10,220 Times in 3,163 Posts
|
install phpmyadmin to make such administrative tasks much easier
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sun Microsystems Announces MySQL 5.1 | malware | News | 0 | Apr 17, 2008 10:11 AM |
| Sun Acquires MySQL, Developer of the World's Most Popular Open Source Database | malware | News | 5 | Jan 16, 2008 08:25 PM |
| Favorite 3rd party software with MySQL | MySQLGeek | General Software | 0 | Dec 31, 2007 08:17 AM |
| Intresting ram prob.. | Solaris17 | Motherboards & Memory | 4 | Sep 2, 2007 02:29 AM |
| Over Heating Prob with ATI X850 XT 256MB | Toastpcs | Graphics Cards | 8 | Jul 28, 2006 09:45 PM |