Wednesday, September 13, 2006

MySQL index lesson

There's a lot to be said for shortcuts. When it comes to making a quick database for my own use with a web interface, I like the Knebel.Net Form Builder. You fill in the form, and it gives you the PHP code to display the MySQL -- and it even gives you the SQL code to create the table! The problem is that the SQL always returns an error, #1067 - Invalid default value for 'id'.

The first line of SQL reads

CREATE TABLE YourTableName (id int(20) DEFAULT '0' NOT NULL AUTO_INCREMENT,

and it happens that you can't have both a default value and auto-increment. So you need to take out the default part.

The first SQL line becomes

CREATE TABLE YourTableName (id int(20) NOT NULL AUTO_INCREMENT,

and the rest works! Back to simple shortcuts.

No comments:

Post a Comment