I have a table that was defined as follows:
CREATE TABLE `Message` ( `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `user_id` integer NOT NULL, `user_to` integer NOT NULL, `top_num` integer NOT NULL, `priority` smallint NOT NULL, `error` varchar(120) NOT NULL, UNIQUE (`user_id`, `user_to`, `top_num`) );
Later I added another msg_type column to it:
ALTER TABLE Message ADD COLUMN msg_type SMALLINT(6) NOT NULL DEFAULT 0;
However, I realized that I needed to change the original UNIQUE constraint to include msg_type . I tried to run
ALTER TABLE Message ADD UNIQUE INDEX (`user_id`, `user_to`, `top_num`, `msg_type`);
but the INSERT in my table is still not working, and the error message indicates that this is because the old uniqueness constraint fails.
When I call describe Messages in mysql, I see the following:
+-----------------+----------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+----------------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | user_id | int(11) | NO | MUL | NULL | | | user_to | int(11) | NO | MUL | NULL | | | top_num | int(11) | NO | MUL | NULL | | | priority | smallint(6) | NO | | NULL | | | error | varchar(120) | NO | | NULL | | | msg_type | smallint(6) | NO | | 0 | | +-----------------+----------------------+------+-----+---------+----------------+
which makes it seem like msg_type really is not part of the constraint ... How can I change the constraint defined by the table, except to recreate the table?
source share