Search code examples
mysqltextkeylongtext

BLOB/TEXT column 'bestilling' used in key specification without a key length


I am trying to make a order system, but I am stuck right now. In the mysql tabel right now, I am using varchar(255) in a column named "bestillinger", but it can only store 255 chars. So I searched a bit, and remembered that i could use longtext or just text, but now when i try to do it, i get a error saying:

#1170 - BLOB/TEXT column 'bestilling' used in key specification without a key length

I have tried to search here and in Google, but got no luck with me.

My MySQL tabel is:

CREATE TABLE IF NOT EXISTS `bestillinger` (
  `id` int(11) NOT NULL,
  `bestilling` TEXT NOT NULL PRIMARY KEY,
  `accepted` varchar(255) DEFAULT NULL,
  UNIQUE KEY `id_bestilling` (`id`,`bestilling`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

I am using UNIQUE KEY because I am using "ON DUPLICATE KEY UPDATE" in my PHP part. But don't mind that.

Thanks in advance.


Solution

  • you can't set a text as a primary key. Mysql only can Index some characters, and type text could be too big to index.

    take a look here: