エラー 42S01 および HY000 で MySQL に単純な外部キーを追加しようとしています。
この外部キーを追加しようとしたときの出力は次のとおりです...
表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
============================