MySQL ERROR 1005 (HY000): Can't create table 'schema_name.table_name' (errno: 150)

今天在按照书上的例子学习Yii的时候发现在创建一个有外键的MySQL表的时候总是报以下错误

ERROR 1005 (HY000): Can't create table '<schema>.<table>' (errno: 150)

但是仅仅从这个错误消息根本得不到任何对排查错误有意义的信息,找了一些文章大多数是说外键表和原表里声明的字段类型不一致,但是都没有给出怎么查出是这个错误的,后来发现原来可以通过运行"SHOW ENGINE INNODB STATUS;"命令,然后在命令结果中的“LATEST FOREIGN KEY ERROR”部分得到具体的错误消息。如下:

... mysql> SHOW ENGINE INNODB STATUS\G *************************** 1. row *************************** Type: InnoDB Name: Status: ===================================== 110920 23:26:39 INNODB MONITOR OUTPUT ===================================== Per second averages calculated from the last 19 seconds ---------- SEMAPHORES ---------- OS WAIT ARRAY INFO: reservation count 46, signal count 46 Mutex spin waits 0, rounds 260, OS waits 13 RW-shared spins 58, OS waits 29; RW-excl spins 5, OS waits 4 ------------------------ LATEST FOREIGN KEY ERROR ------------------------ 110920 23:26:33 Error in foreign key constraint of table trackstar_test/tbl_project_user_role: foreign key (`project_id`) references `tbl_project` (`id`) on delete cascade on update cascade ) engine InnoDB: Cannot resolve table name close to: (`id`) on delete cascade on update cascade ) engine InnoDB ------------ TRANSACTIONS ------------ Trx id counter 0 6375 Purge done for trx's n:o < 0 6353 undo n:o < 0 0 History list length 13 LIST OF TRANSACTIONS FOR EACH SESSION: ---TRANSACTION 0 0, not started, process no 755, OS thread id 2991618928 MySQL thread id 42, query id 383 localhost root SHOW ENGINE INNODB STATUS -------- FILE I/O -------- I/O thread 0 state: waiting for i/o request (insert buffer thread) I/O thread 1 state: waiting for i/o request (log thread) I/O thread 2 state: waiting for i/o request (read thread) I/O thread 3 state: waiting for i/o request (write thread) Pending normal aio reads: 0, aio writes: 0, ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0 Pending flushes (fsync) log: 0; buffer pool: 0 36 OS file reads, 281 OS file writes, 177 OS fsyncs 0.00 reads/s, 0 avg bytes/read, 0.05 writes/s, 0.05 fsyncs/s ------------------------------------- INSERT BUFFER AND ADAPTIVE HASH INDEX ------------------------------------- Ibuf: size 1, free list len 0, seg size 2, 0 inserts, 0 merged recs, 0 merges Hash table size 34679, node heap has 1 buffer(s) 0.00 hash searches/s, 1.16 non-hash searches/s --- LOG --- Log sequence number 0 1774918 Log flushed up to 0 1774918 Last checkpoint at 0 1772796 0 pending log writes, 0 pending chkp writes 128 log i/o's done, 0.05 log i/o's/second ---------------------- BUFFER POOL AND MEMORY ---------------------- Total memory allocated 17596386; in additional pool allocated 960512 Dictionary memory allocated 58096 Buffer pool size 512 Free buffers 468 Database pages 43 Modified db pages 10 Pending reads 0 Pending writes: LRU 0, flush list 0, single page 0 Pages read 35, created 8, written 296 0.00 reads/s, 0.00 creates/s, 0.00 writes/s Buffer pool hit rate 1000 / 1000 -------------- ROW OPERATIONS -------------- 0 queries inside InnoDB, 0 queries in queue 1 read views open inside InnoDB Main thread process no. 755, id 2955570032, state: sleeping Number of rows inserted 60, updated 0, deleted 0, read 159 0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s ---------------------------- END OF INNODB MONITOR OUTPUT ============================


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值