Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tominated

macrumors 68000
Original poster
Jul 7, 2006
1,723
0
Queensland, Australia
I am trying to make anther forum, from another tutorial for my site. I am trying to do it using MAMP, but when i put in the mysql query:
Code:
 CREATE TABLE posts (
   ID int(5) DEFAULT '0' NOT NULL auto_increment,
   TopicID int(5) DEFAULT '0' NOT NULL,
   Name varchar(50) NOT NULL,
   Email varchar(50) NOT NULL,
   Password varchar(50) NOT NULL,
   TimeStamp varchar(10) NOT NULL,
   Post text NOT NULL,
   PRIMARY KEY (ID)
);

CREATE TABLE topics (
   ID int(5) DEFAULT '0' NOT NULL auto_increment,
   TopicName varchar(50) NOT NULL,
   PRIMARY KEY (ID)
);
I comes up with an error saying
#1067 - Invalid default value for 'ID'
The tut is here.
does anybody know what is going on?
 
Looks ok... the only thing I can think of is that tou try to remove the little 's:

PHP:
ID int(5) DEFAULT 0 NOT NULL auto_increment

I've encountered the odd version of phpMyAdmin that has refused to accept my queries before I removed a lot of those...

Edit: Also it doesn't make much sense to say the default is 0 on autoincremented IDs...
 
Try something like this:
PHP:
 CREATE TABLE posts (
   ID int(5) NOT NULL auto_increment,
   TopicID int(5) NOT NULL DEFAULT 0,
   Name varchar(50) NOT NULL,
   Email varchar(50) NOT NULL,
   Password varchar(50) NOT NULL,
   TimeStamp varchar(10) NOT NULL,
   Post text NOT NULL,
   PRIMARY KEY (ID)
) TYPE=MyISAM;

CREATE TABLE topics (
   ID int(5) NOT NULL auto_increment,
   TopicName varchar(50) NOT NULL,
   PRIMARY KEY (ID)
) TYPE=MyISAM;
And let us know which error that causes... :p ;)
 
I've never put a default value for an auto increment; the whole point of it is that the DB automatically sets its value, so there is no default one. Try eliminating that part :)

On a side note, if you plan on making your database portable, try to find a way around intead of using auto increments. They present two problems; the way of handling the last value (I've had issues in PHP+mysql when the last value is returned false in some obscure circumstances), and also I think its easier to just lock the table, find the max number and increment it by one, so you can just port it to Oracle or your database of choice at a later time with less hassle (eg you dont have access to create sequences and triggers).

Let us know if that was the issue, and good luck!
 
I've never put a default value for an auto increment; the whole point of it is that the DB automatically sets its value, so there is no default one. Try eliminating that part :)

On a side note, if you plan on making your database portable, try to find a way around intead of using auto increments. They present two problems; the way of handling the last value (I've had issues in PHP+mysql when the last value is returned false in some obscure circumstances), and also I think its easier to just lock the table, find the max number and increment it by one, so you can just port it to Oracle or your database of choice at a later time with less hassle (eg you dont have access to create sequences and triggers).

Let us know if that was the issue, and good luck!

ummmm..... yes.... did you read that i was following a tutorial?
BTW: What Mitthrawnuruodo said to do worked, but when i try to make a topic it aint working. Don't bother. I'll probably just find a way to integrate vanilla or phorum
 
ummmm..... yes.... did you read that i was following a tutorial?
BTW: What Mitthrawnuruodo said to do worked, but when i try to make a topic it aint working. Don't bother. I'll probably just find a way to integrate vanilla or phorum

Yes, and I also read you were looking for a solution.

Mitthrawnruodo's solution implied basically the same thing; he also eliminated the default value from the auto_increment. I just happenned to bore you more with my explanation, it seems :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.