NameSilo

Invalid default value on mysql.

Spaceship Spaceship
Watch

baris22

Established Member
Impact
1
Hello,

I am triying to install this database but i get an error. Error message is #1067 - Invalid default value for 'article_id'

Here is my database


create table articles (
id int(11) NOT NULL auto_increment,
name varchar(30) NOT NULL default '',
title varchar(40) NOT NULL default'',
content text NOT NULL,
date datetime NOT NULL default'0000-00-00 00:00:00',
ip varchar(20) NOT NULL default'',
primary key (id)
) TYPE=MyISAM auto_increment=1 ;

create table comments (
id int(11) NOT NULL auto_increment,
article_id int(11) NOT NULL default '',
name varchar(30) NOT NULL default '',
website varchar(50) NOT NULL default '',
email varchar(50) NOT NULL default '',
comment text NOT NULL,
date datetime NOT NULL default'0000-00-00 00:00:00',
ip varchar(20) NOT NULL default '',
primary key (id)
) TYPE=MyISAM auto_increment=1 ;


Thanks for your help
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
it works 100% here

you could always try changing article_id int(11) NOT NULL default '', to:-

article_id int(11) default '',
 
0
•••
Although it should generally work it might depend on the MySQL version. But as this is an integer field I'd rather suggest the following definition.

article_id int(11) NOT NULL default 0,
 
0
•••
neroux if he does that there is a potential problem. If for example he has an article with an id of 0 when selecting by article_id he will have 2 to choose from.
 
0
•••
Given that the articles are based on autoincrement values an article should never get a 0. But even if one does, it wouldnt matter.

Anyhow, although '' should work for an integer value it is syntactically wrong. Also allowing NULL could lead to unassociated comments.
 
0
•••
neroux said:
Given that the articles are based on autoincrement values an article should never get a 0. But even if one does, it wouldnt matter.

Anyhow, although '' should work for an integer value it is syntactically wrong. Also allowing NULL could lead to unassociated comments.

Well that is something he would have to weigh up. What would be worse having data within the database that was not associated with a proper record or 1 that could potentially return incorrect data.
 
0
•••
peter@flexiwebhost said:
Well that is something he would have to weigh up. What would be worse having data within the database that was not associated with a proper record or 1 that could potentially return incorrect data.
A NULL value is only recommended when the field does not necessarily need a value, for an association it should never be NULL.
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back