Today, when I learned yii by following the example in the book, I found that the following error is always reported when I create a MySQL table with a foreign key.
Error 1005 (hy000): Can't create table '<schema>. <Table>' (errno: 150)
However, the error message does not contain any information that makes sense for troubleshooting.ArticleMost of them indicate that the types of fields declared in the foreign key table and the original table are inconsistent, but they do not show how to identify this error. Later, they found that they can be run"Show engine InnoDB status;"Command, and then"Latest Foreign key error"To get the specific error message. As follows:
... <Br/> mysql> show engine InnoDB status \ G <br/> ************************ * ** 1. row ************************** <br/> type: innoDB <br/> name: <br/> Status: <br/> ========================================== = <br/> 110920 23:26:39 InnoDB monitor output <br/> ======================== ===========< br/> per second averages calculated from the last 19 seconds <br/> ---------- <br/> semaphores <br/> ---------- <br/> OS wait array info: reservation Count 46, signal Count 46 <br/> mutex spin waits 0, rounds 260, OS waits 13 <br/> RW-shared spins 58, OS waits 29; RW-excl spins 5, OS waits 4 <br/> failed <br/> latest foreign key error <br/> ---------------------- <br/> 110920 23:26:33 error in foreign key constraint of table trackstar_test/tbl_project_user_role: <br/> foreign key ('Project _ id') References 'tbl _ project' ('id') on Delete cascade on update cascade <br/>) engine InnoDB: <br/> cannot resolve table name close to: <br/> ('id') on Delete cascade on update cascade <br/>) engine InnoDB <br/> ------------ <br/> transactions <br/> ------------ <br/> trx id counter 0 6375 <br/> purge done for TRX's N: O <0 6353 undo N: O <0 0 <br/> history list length 13 <br/> list of transactions for each session: <br/> --- transaction 0 0, not started, process no 755, OS thread ID 2991618928 <br/> MySQL thread ID 42, query ID 383 localhost root <br/> show engine InnoDB status <br/> -------- <br/> file I/O <br/> -------- <br/> I/O Thread 0 state: waiting for I/O Request (insert buffer thread) <br/> I/O thread 1 State: Waiting For I/O Request (log thread) <br/> I/O thread 2 State: Waiting For I/O Request (read thread) <br/> I/O thread 3 state: waiting for I/O Request (write thread) <br/> pending normal AIO reads: 0, Aio writes: 0, <br/> ibuf AIO reads: 0, log I/O's: 0, sync I/O's: 0 <br/> pending flushes (fsync) log: 0; Buffer Pool: 0 <br/> 36 OS file reads, 281 OS file writes, 177 OS fsyncs <br/> 0.00 reads/s, 0 AVG Bytes/read, 0.05 writes/s, 0.05 fsyncs/S <br/> values <br/> insert buffer and adaptive hash index <br/> ------------------------------------- <br/> ibuf: Size 1, Free List Len 0, SEG size 2, <br/> 0 inserts, 0 merged RECs, 0 merges <br/> hash table size 34679, node Heap has 1 buffer (s) <br/> 0.00 hash searches/s, 1.16 non-Hash searches/S <br/> --- <br/> log sequence number 0 1774918 <br/> log flushed up to 0 1774918 <br/> Last checkpoint at 0 1772796 <br/> 0 pending log writes, 0 pending chkp writes <br/> 128 log I/O's done, 0.05 log I/O's/second <br/> -------------------- <br/> buffer pool and memory <br/> ---------------------- <br/> total memory allocated 17596386; in additional pool allocated 960512 <br/> Dictionary Memory allocated 58096 <br/> buffer pool size 512 <br/> free buffers 468 <br/> database pages 43 <br/> modified DB pages 10 <br/> pending reads 0 <br/> pending writes: LRU 0, flush list 0, single page 0 <br/> pages read 35, created 8, written 296 <br/> 0.00 reads/s, 0.00 creates/s, 0.00 writes/S <br/> buffer pool hit rate 1000/1000 <br/> -------------- <br/> Row Operations <br/> ------------ <br/> 0 queries inside InnoDB, 0 queries in queue <br/> 1 read views open inside InnoDB <br/> main thread process no. 755, Id 2955570032, state: Sleeping <br/> Number of rows inserted 60, updated 0, deleted 0, read 159 <br/> 0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/S <br/> -------------------------- <br/> end of InnoDB monitor output <br/>============ ===========< br/>