2012-08-09 81 views
3

我有以下的現有表,因爲在這裏看到..錯誤「表」 架構表」,並稱當已經存在的外鍵

顯示創建表ExpeditedAddress。

CREATE TABLE `expeditedaddress` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT, 
    `description` varchar(255) NOT NULL, 
    `address` varchar(255) NOT NULL, 
    `city` varchar(255) NOT NULL, 
    `country` varchar(255) NOT NULL, 
    `stateProvince` varchar(255) NOT NULL, 
    `zipPostal` varchar(255) NOT NULL, 
    `brokerageId` bigint(20) NOT NULL, 
    `timezoneCode` varchar(100) NOT NULL, 
    `productionFacilityId` bigint(20) NOT NULL, 
    `deliveryCutoffTime` time NOT NULL, 
    `deliveredByTime` time NOT NULL, 
    `daysToDeliver` int(11) NOT NULL, 
    PRIMARY KEY (`id`), 
    KEY `FK_ExpeditedAddress_Brokerage_ID` (`brokerageId`), 
    KEY `FK_ExpeditedAddress_Country_StateProvince` (`country`,`stateProvince`), 
    CONSTRAINT `ExpeditedAddress_ibfk_1` FOREIGN KEY (`brokerageId`) REFERENCES `brokerage` (`id`), 
    CONSTRAINT `ExpeditedAddress_ibfk_2` FOREIGN KEY (`country`, `stateProvince`) REFERENCES `stateprovince` (`countryName`, `name`) 
) ENGINE=InnoDB AUTO_INCREMENT=149 DEFAULT CHARSET=utf8; 

它引用此表

顯示創建表ProductionFacility;

CREATE TABLE `productionfacility` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT, 
    `description` varchar(255) NOT NULL, 
    `address` varchar(255) NOT NULL, 
    `city` varchar(255) NOT NULL, 
    `country` varchar(255) NOT NULL, 
    `stateProvince` varchar(255) NOT NULL, 
    `zipPostal` varchar(255) NOT NULL, 
    `timezoneCode` varchar(100) NOT NULL, 
    `workingWeek` varchar(255) NOT NULL, 
    PRIMARY KEY (`id`), 
    KEY `FK_ProductionFacility_Country_StateProvince` (`country`,`stateProvince`), 
    CONSTRAINT `productionfacility_ibfk_1` FOREIGN KEY (`country`, `stateProvince`) REFERENCES `stateprovince` (`countryName`, `name`) 
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8; 

然後,當我嘗試添加一個外鍵,這樣的... ...

alter table ExpeditedAddress add foreign key FK_ExpeditedAddress_Productionfacility(productionFacilityId) references ProductionFacility(id); 

我得到以下...

[2012-08-09 15:39:22] [42S01][1050] Table '.\realtorprint_dev_prod\expeditedaddress' already exists 
[2012-08-09 15:39:22] [HY000][1025] Error on rename of '.\realtorprint_dev_prod\#sql-1d74_710a' to '.\realtorprint_dev_prod\expeditedaddress' (errno: -1) 
[2012-08-09 15:39:22] [42S01][1050] Table '.\realtorprint_dev_prod\expeditedaddress' already exists 

似乎是一個非常奇怪的錯誤要得到。列的類型都是「bigint(20)非空」。這兩個表都是InnoDB。引用的列是主鍵。

有沒有人有任何想法?

而且,這裏是運行

顯示引擎InnoDB的狀態的結果;

===================================== 
120809 15:45:41 INNODB MONITOR OUTPUT 
===================================== 
Per second averages calculated from the last 54 seconds 
----------------- 
BACKGROUND THREAD 
----------------- 
srv_master_thread loops: 9322 1_second, 9321 sleeps, 846 10_second, 894 background, 894 flush 
srv_master_thread log flush and writes: 9323 
---------- 
SEMAPHORES 
---------- 
OS WAIT ARRAY INFO: reservation count 520, signal count 520 
Mutex spin waits 197, rounds 836, OS waits 12 
RW-shared spins 499, rounds 14942, OS waits 498 
RW-excl spins 2, rounds 242, OS waits 8 
Spin rounds per wait: 4.24 mutex, 29.94 RW-shared, 121.00 RW-excl 
------------------------ 
LATEST FOREIGN KEY ERROR 
------------------------ 
120809 15:34:11 Transaction: 
TRANSACTION 40CE, ACTIVE 0 sec inserting, thread declared inside InnoDB 485 
mysql tables in use 2, locked 2 
7 lock struct(s), heap size 1248, 16 row lock(s), undo log entries 7 
MySQL thread id 28938, OS thread handle 0x16d4, query id 350923 localhost 127.0.0.1 rpuser copy to tmp table 
alter table ExpeditedAddress add foreign key FK_ExpeditedAddress_Productionfacility(id) references ProductionFacility(id) 
Foreign key constraint fails for table `realtorprint_dev_prod`.`#sql-1d74_710a`: 
, 
    CONSTRAINT `#sql-1d74_710a_ibfk_1` FOREIGN KEY (`id`) REFERENCES `productionfacility` (`id`) 
Trying to add in child table, in index `PRIMARY` tuple: 
DATA TUPLE: 15 fields; 
0: len 8; hex 8000000000000008; asc   ;; 
1: len 6; hex 0000000040ce; asc  @ ;; 
2: len 7; hex a3000005f90176; asc  v;; 
3: len 12; hex 536f757468204f6666696365; asc South Office;; 
4: len 25; hex 233235322c2031313438382d20323420537472656574205345; asC#252, 11488- 24 Street SE;; 
5: len 7; hex 43616c67617279; asc Calgary;; 
6: len 6; hex 43616e616461; asc Canada;; 
7: len 7; hex 416c6265727461; asc Alberta;; 
8: len 7; hex 54325a20344339; asc T2Z 4C9;; 
9: len 8; hex 8000000000000012; asc   ;; 
10: len 16; hex 416d65726963612f45646d6f6e746f6e; asc America/Edmonton;; 
11: len 8; hex 8000000000000001; asc   ;; 
12: len 3; hex 81adb0; asc ;; 
13: len 3; hex 829810; asc ;; 
14: len 4; hex 80000001; asc  ;; 

But in parent table `realtorprint_dev_prod`.`productionfacility`, in index `PRIMARY`, 
the closest match we can find is record: 
PHYSICAL RECORD: n_fields 11; compact format; info bits 0 
0: len 8; hex 8000000000000007; asc   ;; 
1: len 6; hex 00000000401f; asc  @ ;; 
2: len 7; hex b6000003a10176; asc  v;; 
3: len 16; hex 4461746147726f7570204c6f6e646f6e; asc DataGroup London;; 
4: len 21; hex 313837302043686561707369646520537472656574; asc 1870 Cheapside Street;; 
5: len 6; hex 4c6f6e646f6e; asc London;; 
6: len 6; hex 43616e616461; asc Canada;; 
7: len 7; hex 4f6e746172696f; asc Ontario;; 
8: len 7; hex 4e355620334537; asc N5V 3E7;; 
9: len 15; hex 416d65726963612f546f726f6e746f; asc America/Toronto;; 
10: len 0; hex ; asc ;; 

InnoDB: Renaming table `realtorprint_dev_prod`.`#sql-1d74_710a` to `realtorprint_dev_prod`.`expeditedaddress` failed! 
InnoDB: Renaming table `realtorprint_dev_prod`.`#sql-1d74_710a` to `realtorprint_dev_prod`.`expeditedaddress` failed! 
InnoDB: Renaming table `realtorprint_dev_prod`.`#sql-1d74_710a` to `realtorprint_dev_prod`.`expeditedaddress` failed! 
InnoDB: Renaming table `realtorprint_dev_prod`.`#sql-1d74_710b` to `realtorprint_dev_prod`.`expeditedaddress` failed! 
------------ 
TRANSACTIONS 
------------ 
Trx id counter 40FD 
Purge done for trx's n:o < 40F2 undo n:o < 0 
History list length 827 
LIST OF TRANSACTIONS FOR EACH SESSION: 
---TRANSACTION 40F3, not started 
MySQL thread id 28939, OS thread handle 0x2ed8, query id 350949 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 
1363 OS file reads, 17403 OS file writes, 4157 OS fsyncs 
0.00 reads/s, 0 avg bytes/read, 0.11 writes/s, 0.11 fsyncs/s 
------------------------------------- 
INSERT BUFFER AND ADAPTIVE HASH INDEX 
------------------------------------- 
Ibuf: size 1, free list len 0, seg size 2, 11 merges 
merged operations: 
insert 11, delete mark 0, delete 0 
discarded operations: 
insert 0, delete mark 0, delete 0 
Hash table size 1458971, node heap has 15 buffer(s) 
3.54 hash searches/s, 12.39 non-hash searches/s 
--- 
LOG 
--- 
Log sequence number 121733086 
Log flushed up to 121733086 
Last checkpoint at 121601659 
0 pending log writes, 0 pending chkp writes 
2674 log i/o's done, 0.11 log i/o's/second 
---------------------- 
BUFFER POOL AND MEMORY 
---------------------- 
Total memory allocated 754434048; in additional pool allocated 0 
Dictionary memory allocated 795806 
Buffer pool size 44992 
Free buffers  42494 
Database pages  2483 
Old database pages 896 
Modified db pages 36 
Pending reads 0 
Pending writes: LRU 0, flush list 0, single page 0 
Pages made young 335, not young 0 
0.00 youngs/s, 0.00 non-youngs/s 
Pages read 1352, created 1131, written 13915 
0.00 reads/s, 0.00 creates/s, 0.00 writes/s 
Buffer pool hit rate 1000/1000, young-making rate 0/1000 not 0/1000 
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s 
LRU len: 2483, 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 7616, state: sleeping 
Number of rows inserted 194766, updated 699, deleted 143, read 806318 
2.74 inserts/s, 0.00 updates/s, 0.00 deletes/s, 2.74 reads/s 
---------------------------- 
END OF INNODB MONITOR OUTPUT 
============================ 
+0

'show engine innodb status'總是一個很好的開始,看看你是否有錯誤。 – derobert 2012-08-09 21:42:44

回答

0

如果你看看你的「最新的外鍵錯誤」下,那漫長的抱怨,你要添加外鍵被侵犯:現有的數據不符合外鍵約束。 (我不是100%肯定這就是它的說法,它可能是在抱怨指數腐敗,在這種情況下,你需要弄清楚你的指數如何變壞並重建指數,但我認爲不是。認爲自從上次看到它以來,他們只是更改了違反外鍵的錯誤消息)。

相關問題