手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

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

[日期:2011-09-22] 来源:Linux社区  作者:kongxx [字体:大 中 小]
在按照书上的例子学习Yii的时候发现在创建一个有外键的MySQL表的时候总是报以下错误
  1. ERROR 1005 (HY000): Can't create table '<schema>.<table>' (errno: 150)  

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

  1. ...  
  2. mysql> SHOW ENGINE INNODB STATUS\G  
  3. *************************** 1. row ***************************  
  4.   Type: InnoDB  
  5.   Name:   
  6. Status:   
  7. =====================================  
  8. 110920 23:26:39 INNODB MONITOR OUTPUT  
  9. =====================================  
  10. Per second averages calculated from the last 19 seconds  
  11. ----------  
  12. SEMAPHORES  
  13. ----------  
  14. OS WAIT ARRAY INFO: reservation count 46, signal count 46  
  15. Mutex spin waits 0, rounds 260, OS waits 13  
  16. RW-shared spins 58, OS waits 29; RW-excl spins 5, OS waits 4  
  17. ------------------------  
  18. LATEST FOREIGN KEY ERROR  
  19. ------------------------  
  20. 110920 23:26:33 Error in foreign key constraint of table trackstar_test/tbl_project_user_role:  
  21. foreign key (`project_id`) references `tbl_project` (`id`) on delete cascade on update cascade  
  22. ) engine InnoDB:  
  23. Cannot resolve table name close to:  
  24.  (`id`) on delete cascade on update cascade  
  25. ) engine InnoDB  
  26. ------------  
  27. TRANSACTIONS  
  28. ------------  
  29. Trx id counter 0 6375  
  30. Purge done for trx's n:o < 0 6353 undo n:o < 0 0  
  31. History list length 13  
  32. LIST OF TRANSACTIONS FOR EACH SESSION:  
  33. ---TRANSACTION 0 0, not started, process no 755, OS thread id 2991618928  
  34. MySQL thread id 42, query id 383 localhost root  
  35. SHOW ENGINE INNODB STATUS  
  36. --------  
  37. FILE I/O  
  38. --------  
  39. I/O thread 0 state: waiting for i/o request (insert buffer thread)  
  40. I/O thread 1 state: waiting for i/o request (log thread)  
  41. I/O thread 2 state: waiting for i/o request (read thread)  
  42. I/O thread 3 state: waiting for i/o request (write thread)  
  43. Pending normal aio reads: 0, aio writes: 0,  
  44.  ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0  
  45. Pending flushes (fsync) log: 0; buffer pool: 0  
  46. 36 OS file reads, 281 OS file writes, 177 OS fsyncs  
  47. 0.00 reads/s, 0 avg bytes/read, 0.05 writes/s, 0.05 fsyncs/s  
  48. -------------------------------------  
  49. INSERT BUFFER AND ADAPTIVE HASH INDEX  
  50. -------------------------------------  
  51. Ibuf: size 1, free list len 0, seg size 2,  
  52. 0 inserts, 0 merged recs, 0 merges  
  53. Hash table size 34679, node heap has 1 buffer(s)  
  54. 0.00 hash searches/s, 1.16 non-hash searches/s  
  55. ---  
  56. LOG  
  57. ---  
  58. Log sequence number 0 1774918  
  59. Log flushed up to   0 1774918  
  60. Last checkpoint at  0 1772796  
  61. 0 pending log writes, 0 pending chkp writes  
  62. 128 log i/o's done, 0.05 log i/o's/second  
  63. ----------------------  
  64. BUFFER POOL AND MEMORY  
  65. ----------------------  
  66. Total memory allocated 17596386; in additional pool allocated 960512  
  67. Dictionary memory allocated 58096  
  68. Buffer pool size   512  
  69. Free buffers       468  
  70. Database pages     43  
  71. Modified db pages  10  
  72. Pending reads 0  
  73. Pending writes: LRU 0, flush list 0, single page 0  
  74. Pages read 35, created 8, written 296  
  75. 0.00 reads/s, 0.00 creates/s, 0.00 writes/s  
  76. Buffer pool hit rate 1000 / 1000  
  77. --------------  
  78. ROW OPERATIONS  
  79. --------------  
  80. 0 queries inside InnoDB, 0 queries in queue  
  81. 1 read views open inside InnoDB  
  82. Main thread process no. 755, id 2955570032, state: sleeping  
  83. Number of rows inserted 60, updated 0, deleted 0, read 159  
  84. 0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s  
  85. ----------------------------  
  86. END OF INNODB MONITOR OUTPUT  
  87. ============================  
linux
相关资讯       MySQL教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款