Eto*_*Jr. 4 mysql database mysql-error-1091
我在 CentOs 5 上使用 mysql-server-5.0.45-7.el5。
在我的数据库中,有一个表,我不知道什么时候创建了一个 MUL 键(数据库是共享的,在一个组的控制下),现在当我尝试插入一些值时,我得到一个如图所示的错误以上:
Duplicate entry '2-1-2004-09-11 13:13:41.526' for key 2:INSERT INTO ephemeris SET
EPH_TYPE_ID = 1, FILENAME = 'CBERS_2_CCD1_DRD_2004_09_11.13_13_23', ID = 0,
IS_NEW = 1, SATELLITE_ID = 2, TIME = '2004-09-11 13:13:41.526'
Run Code Online (Sandbox Code Playgroud)
我有一次遇到这个错误,我ALTER TABLE ephemeris DROP INDEX SATELLITE_ID;
第一次尝试它有效,但现在出现了相同的约束,它根本不起作用。
表结构(续):
mysql> show columns from ephemeris;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| SATELLITE_ID | int(11) | NO | MUL | 0 | |
| EPH_TYPE_ID | int(11) | NO | | 0 | |
Run Code Online (Sandbox Code Playgroud)
当我键入ALTER TABLE命令时,mysql 返回为:
mysql> ALTER TABLE ephemeris DROP INDEX ephemeris.SATELLITE_ID ;
ERROR 1091 (42000): Can't DROP 'SATELLITE_ID'; check that column/key exists
Run Code Online (Sandbox Code Playgroud)
有人已经收到此错误了吗?有什么帮助吗?
Rgds。
小智 5
You need to first drop the foreign key constraint, then drop the index.
mysql> show create table a;
| CREATE TABLE `a` (
`id` varchar(20) DEFAULT NULL,
`sal` int(20) DEFAULT NULL,
`b_id` varchar(20) DEFAULT NULL,
KEY `b_id` (`b_id`),
CONSTRAINT `a_ibfk_1` FOREIGN KEY (`b_id`) REFERENCES `b` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
mysql> alter table a drop foreign key `a_ibfk_1`;
Query OK, 0 rows affected (0.10 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table a drop index `b_id`;
Query OK, 0 rows affected (0.23 sec)
Records: 0 Duplicates: 0 Warnings: 0
Run Code Online (Sandbox Code Playgroud)