The command that I use to CREATE
my TABLE
is:
CREATE TABLE carts(order_id TEXT(14), items TEXT, shipping INT, price INT
I'd like to set 'order_id' as my primary key. I've tried to ALTER
the TABLE
with:
ALTER TABLE `carts` ADD PRIMARY KEY(order_id)
But that returns the error:
#1170 - BLOB/TEXT column 'order_id' used in key specification without a key length
I understand that means that the length isn't being set correctly in the initial setup, so I tried:
ALTER TABLE `carts` ADD PRIMARY KEY(order_id(14))
Which returns the same error. The type defined in phpmyadmin is 'tinytext'; I was expecting to see TEXT(14)
.
I'm performing all of these commands via PDO in PHP. What's the correct way to set the column 'order_id' as my TABLE
's primary key?