Forum Moderators: open

Message Too Old, No Replies

Invalid default value for.

         

jshpik1

7:29 pm on Sep 3, 2007 (gmt 0)

10+ Year Member



I ran this sql query:


CREATE TABLE phpbb_logos (id MEDIUMINT (8) UNSIGNED DEFAULT '0' NOT NULL AUTO_INCREMENT, page INT (11) DEFAULT '0', image VARCHAR (255) DEFAULT '0', cat_id MEDIUMINT(8) UNSIGNED, PRIMARY KEY(id), UNIQUE(id), INDEX(id))

Got this error:


Error

SQL-query :

CREATE TABLE phpbb_logos(

id MEDIUMINT( 8 ) UNSIGNED DEFAULT '0' NOT NULL AUTO_INCREMENT ,
page INT( 11 ) DEFAULT '0',
image VARCHAR( 255 ) DEFAULT '0',
cat_id MEDIUMINT( 8 ) UNSIGNED,
PRIMARY KEY ( id ) ,
UNIQUE (
id
),
INDEX ( id )
)

MySQL said:

Invalid default value for 'id'

So how do I fix this? I've search online and these forums. Thanks.

Discovery

7:06 am on Sep 4, 2007 (gmt 0)

10+ Year Member



error :

CREATE TABLE phpbb_logos (id MEDIUMINT (8) UNSIGNED DEFAULT '0' NOT NULL AUTO_INCREMENT, page INT (11) DEFAULT '0', image VARCHAR (255) DEFAULT '0', cat_id MEDIUMINT(8) UNSIGNED, PRIMARY KEY(id), UNIQUE(id), INDEX(id))

sol :


CREATE TABLE phpbb_logos (id MEDIUMINT (8) UNSIGNED NOT NULL AUTO_INCREMENT, page INT (11) DEFAULT '0', image VARCHAR (255) DEFAULT '0', cat_id MEDIUMINT(8) UNSIGNED, PRIMARY KEY(id), UNIQUE(id), INDEX(id))

or


CREATE TABLE phpbb_logos (id MEDIUMINT (8) UNSIGNED DEFAULT '0' NOT NULL , page INT (11) DEFAULT '0', image VARCHAR (255) DEFAULT '0', cat_id MEDIUMINT(8) UNSIGNED, PRIMARY KEY(id), UNIQUE(id), INDEX(id))

you can't say DEFAULT '0' and AUTO_INCREMENT. it should be AUTO_INCREMENT or DEFAULT '0'

[edited by: Discovery at 7:07 am (utc) on Sep. 4, 2007]

jshpik1

11:43 am on Sep 4, 2007 (gmt 0)

10+ Year Member



Both those commands perform the same function?

Discovery

2:32 pm on Sep 10, 2007 (gmt 0)

10+ Year Member



no,
if you say DEFAULT '0'
it mean, if you will not provide value for that field it will take 0.

and if you say AUTO_INCREMENT.

it mean, if you will not provide value for that field it will take next highest value.