The command I use for CREATEmy TABLE:
CREATE TABLE carts(order_id TEXT(14), items TEXT, shipping INT, price INT
I would like to set "order_id" as the primary key. I tried ALTER TABLEusing:
ALTER TABLE `carts` ADD PRIMARY KEY(order_id)
But this returns an error:
#1170 - BLOB/TEXT column 'order_id' used in key specification without a key length
I understand that this means that the length is not set correctly in the initial setup, so I tried:
ALTER TABLE `carts` ADD PRIMARY KEY(order_id(14))
It returns the same error. The type defined in phpmyadmin is "tinytext"; I expected to see TEXT(14).
I execute all these commands through PDO in PHP. What is the correct way to set the column "order_id" as my primary key TABLE?
Jamus source
share