2012-10-23 48 views
1

我想在MySQL中添加一个简单的外键与错误42S01和HY000无法在MySQL中添加外键5.5.25

这里是输出,当我尝试添加该外键...

表1

show create table Agency; 

CREATE TABLE `agency` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT, 
    `name` varchar(255) NOT NULL, 
    `paymentTypeName` varchar(255) NOT NULL, 
    `enforceUserList` tinyint(1) NOT NULL, 
    `templatesRelativePath` varchar(255) NOT NULL, 
    `siteName` varchar(100) NOT NULL, 
    `supportsUSA` tinyint(1) NOT NULL, 
    `supportsCAN` tinyint(1) NOT NULL, 
    `defaultCountry` varchar(40) NOT NULL, 
    PRIMARY KEY (`id`), 
    KEY `FK_Agency_PaymentType` (`paymentTypeName`), 
    CONSTRAINT `Agency_ibfk_1` FOREIGN KEY (`paymentTypeName`) REFERENCES `paymenttype` (`name`) 
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8; 

表2

show create table Country; 

CREATE TABLE `country` (
    `name` varchar(40) NOT NULL, 
    `abbreviation` varchar(4) NOT NULL, 
    `enabled` tinyint(1) NOT NULL, 
    PRIMARY KEY (`name`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

尝试添加外键

alter table Agency add foreign key FK_Agency_Country_Name(defaultCountry) references Country(name); 

[2012-10-23 14:04:24] [42S01][1050] Table '.\realtorprint_dev_4982\agency' already exists 
[2012-10-23 14:04:24] [HY000][1025] Error on rename of '.\realtorprint_dev_4982\#sql-2b80_1141' to '.\realtorprint_dev_4982\agency' (errno: -1) 
[2012-10-23 14:04:24] [42S01][1050] Table '.\realtorprint_dev_4982\agency' already exists 

显示引擎InnoDB的状态(试图添加外键后)

===================================== 
121023 14:06:58 INNODB MONITOR OUTPUT 
===================================== 
Per second averages calculated from the last 20 seconds 
----------------- 
BACKGROUND THREAD 
----------------- 
srv_master_thread loops: 863 1_second, 863 sleeps, 78 10_second, 84 background, 84 flush 
srv_master_thread log flush and writes: 864 
---------- 
SEMAPHORES 
---------- 
OS WAIT ARRAY INFO: reservation count 30, signal count 30 
Mutex spin waits 11, rounds 183, OS waits 1 
RW-shared spins 26, rounds 780, OS waits 26 
RW-excl spins 3, rounds 132, OS waits 3 
Spin rounds per wait: 16.64 mutex, 30.00 RW-shared, 44.00 RW-excl 
------------------------ 
LATEST FOREIGN KEY ERROR 
------------------------ 
InnoDB: Renaming table `realtorprint_dev_4982`.`#sql-2b80_7` to `realtorprint_dev_4982`.`agency` failed! 
InnoDB: Renaming table `realtorprint_dev_4982`.`#sql-2b80_8` to `realtorprint_dev_4982`.`agency` failed! 
InnoDB: Renaming table `realtorprint_dev_4982`.`#sql-2b80_8` to `realtorprint_dev_4982`.`agency` failed! 
InnoDB: Renaming table `realtorprint_dev_4982`.`#sql-2b80_8` to `realtorprint_dev_4982`.`agency` failed! 
InnoDB: Renaming table `realtorprint_dev_4982`.`#sql-2b80_8` to `realtorprint_dev_4982`.`agency` failed! 
InnoDB: Renaming table `realtorprint_dev_4982`.`#sql-2b80_8` to `realtorprint_dev_4982`.`agency` failed! 
InnoDB: Renaming table `realtorprint_dev_4982`.`#sql-2b80_1141` to `realtorprint_dev_4982`.`agency` failed! 
InnoDB: Renaming table `realtorprint_dev_4982`.`#sql-2b80_1141` to `realtorprint_dev_4982`.`agency` failed! 
------------ 
TRANSACTIONS 
------------ 
Trx id counter 17517 
Purge done for trx's n:o < 17517 undo n:o < 0 
History list length 1149 
LIST OF TRANSACTIONS FOR EACH SESSION: 
---TRANSACTION 1750D, not started 
MySQL thread id 4417, OS thread handle 0x2330, query id 49431 localhost 127.0.0.1 rpuser 
show engine InnoDB status 
-------- 
FILE I/O 
-------- 
I/O thread 0 state: wait Windows aio (insert buffer thread) 
I/O thread 1 state: wait Windows aio (log thread) 
I/O thread 2 state: wait Windows aio (read thread) 
I/O thread 3 state: wait Windows aio (read thread) 
I/O thread 4 state: wait Windows aio (read thread) 
I/O thread 5 state: wait Windows aio (read thread) 
I/O thread 6 state: wait Windows aio (write thread) 
I/O thread 7 state: wait Windows aio (write thread) 
I/O thread 8 state: wait Windows aio (write thread) 
I/O thread 9 state: wait Windows aio (write thread) 
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] , 
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0 
Pending flushes (fsync) log: 0; buffer pool: 0 
697 OS file reads, 596 OS file writes, 184 OS fsyncs 
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s 
------------------------------------- 
INSERT BUFFER AND ADAPTIVE HASH INDEX 
------------------------------------- 
Ibuf: size 1, free list len 5, seg size 7, 7 merges 
merged operations: 
insert 6, delete mark 1, delete 0 
discarded operations: 
insert 0, delete mark 0, delete 0 
Hash table size 1458971, node heap has 3 buffer(s) 
0.00 hash searches/s, 0.00 non-hash searches/s 
--- 
LOG 
--- 
Log sequence number 6730688792 
Log flushed up to 6730688792 
Last checkpoint at 6730688792 
0 pending log writes, 0 pending chkp writes 
119 log i/o's done, 0.00 log i/o's/second 
---------------------- 
BUFFER POOL AND MEMORY 
---------------------- 
Total memory allocated 754434048; in additional pool allocated 0 
Dictionary memory allocated 272477 
Buffer pool size 44992 
Free buffers  44282 
Database pages  707 
Old database pages 279 
Modified db pages 0 
Pending reads 0 
Pending writes: LRU 0, flush list 0, single page 0 
Pages made young 0, not young 0 
0.00 youngs/s, 0.00 non-youngs/s 
Pages read 686, created 21, written 446 
0.00 reads/s, 0.00 creates/s, 0.00 writes/s 
No buffer pool page gets since the last printout 
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s 
LRU len: 707, unzip_LRU len: 0 
I/O sum[0]:cur[0], unzip sum[0]:cur[0] 
-------------- 
ROW OPERATIONS 
-------------- 
0 queries inside InnoDB, 0 queries in queue 
1 read views open inside InnoDB 
Main thread id 11192, state: waiting for server activity 
Number of rows inserted 136, updated 7, deleted 5, read 84358 
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s 
---------------------------- 
END OF INNODB MONITOR OUTPUT 
============================ 
+0

它可能是机构vs. \ agency \'? –

+0

不,我在Windows上都尝试过,MySQL表名不区分大小写。 – benstpierre

+0

在将现有数据库与Workbench模型同步时,类似消息的问题通过一个奇怪的操作解决 - 将某些约束的名称更改为其他内容。这是为了以防万一。可能完全不同;问题的关键是消息与问题无关。 –

回答

0

如果我用比 '代理' 以外的东西你DML查询工作对于那个表的名字(我尝试过agenc,agence,agencie,他们都工作过,但是机构没有,每次都使用新的数据库)。所以恭喜!我想你已经在MySQL中发现了一个非常模糊的错误。如果你想提交它,你应该包括这个语句的再现脚本,以便它是完整的:

CREATE TABLE `paymenttype`(`name` VARCHAR(255) NOT NULL, PRIMARY KEY (`name`)) DEFAULT CHARSET=utf8; 

http://bugs.mysql.com/

稍微题外话:我只对之前已经提交了同样默默无闻的bug到MySQL让他们被标记为没有链接的奇怪错误ID的重复项,并且不会显示在错误跟踪器中,所以大概在甲骨文掌舵的情况下,现在有一个“高级”错误跟踪器......也许如果我成为企业合作伙伴我可以为我的bug找到补丁!好玩的东西!