[vox-tech] Altering Columns in MySQL on RedHat

Marc Elliot Hall vox-tech@lists.lugod.org
Mon, 01 Dec 2003 20:31:25 -0800


I've got a RedHat 8 box running MySQL 3.23.55. One of my tables has a 
field with 'varchar(250)' as the data type.

mysql> desc foo;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | int(11)      |      | UNI | NULL    | auto_increment |
| sku         | varchar(10)  |      | PRI |         |                |
| bar         | varchar(250) |      | MUL |         |                |
| name        | text         | YES  |     | NULL    |                |
| etc...      | int(11)      | YES  |     | NULL    |                |


Unfortunately, 250 characters is insufficient for the data I want to put 
into this field. So, I want to change it to 'blob' or 'text'. However, 
when I use:

mysql> alter table foo modify bar text not null;

I receive back the error:

ERROR 1170: BLOB column 'bar' used in key specification without a key length

I've tried adding a new column:

mysql> alter table foo add barnew text not null;
Query OK, 19543 rows affected (3.84 sec)
Records: 19543  Duplicates: 0  Warnings: 0

and the new column shows up:

| barnew      | text         |      |     |         |                |
+-------------+--------------+------+-----+---------+----------------+

However, I have thus far been unable to get the values out of 'bar' and 
into 'barnew'; I'm pro'ly just being boneheaded about this and missing 
something obvious. :^)

My question is this: how do I change the data type of a column that's 
part of the key? Google and http://www.mysql.com/doc/ have been (so far) 
not very helpful. Any advice is appreciated!