sql column length error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

sql column length error

Post by lipun4u »

I have a requirement that a table has to contain 3 columns, user_id, url and name. I want to make the url primary key. Go throw the following sql query.

Code: Select all

mysql> CREATE TABLE blog_details (
    -> user_id INT(11),
    -> blogname VARCHAR(1024),
    -> blogurl VARCHAR(1024) NOT NULL,
    -> PRIMARY KEY(blogurl),
    -> FOREIGN KEY (user_id) REFERENCES login(user_id)
    -> ON DELETE CASCADE
    -> );
ERROR 1071 (42000): Specified KEY was too long; max KEY length IS 767 bytes
How can I fix the above error ???
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: sql column length error

Post by Mark Baker »

Besides asking why blogurl should be your primary key, and not simply uniquely indexed, your only solution is

Code: Select all

blogurl VARCHAR(767) NOT NULL
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

Re: sql column length error

Post by lipun4u »

thank you
Post Reply