Mysql 错误:错误1215:无法添加外键约束

Mysql 错误:错误1215:无法添加外键约束,mysql,Mysql,我得到错误:错误:错误1215:无法添加外键约束 我读过其他类似的话题,但显然我无法解决这个问题 代码生成如下(它应该可以完美地工作,该死的): InnoDB状态显示如下: ===================================== 2013-05-26 13:07:32 460 INNODB MONITOR OUTPUT ===================================== Per second averages calculated from the l

我得到错误:错误:错误1215:无法添加外键约束

我读过其他类似的话题,但显然我无法解决这个问题

代码生成如下(它应该可以完美地工作,该死的):

InnoDB状态显示如下:

=====================================
2013-05-26 13:07:32 460 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 52 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 8 srv_active, 0 srv_shutdown, 7450 srv_idle
srv_master_thread log flush and writes: 7458
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 20
OS WAIT ARRAY INFO: signal count 19
Mutex spin waits 2, rounds 0, OS waits 0
RW-shared spins 19, rounds 570, OS waits 19
RW-excl spins 1, rounds 30, OS waits 1
Spin rounds per wait: 0.00 mutex, 30.00 RW-shared, 30.00 RW-excl
------------------------
LATEST FOREIGN KEY ERROR
------------------------
2013-05-26 13:07:16 f0c Error in foreign key constraint of table foilmaster/contactdata:
there is no index in referenced table which would contain
the columns as the first columns, or the data types in the
referenced table do not match the ones in table. Constraint:
,
  CONSTRAINT "ID" FOREIGN KEY ("ID") REFERENCES "company" ("ID")
The index in the foreign key in table is "PRIMARY"
See http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html
for correct foreign key definition.
------------
TRANSACTIONS
------------
Trx id counter 3386
Purge done for trx's n:o < 3386 undo n:o < 0 state: running but idle
History list length 240
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 12, OS thread handle 0x460, query id 394 localhost 127.0.0.1 root init
SHOW ENGINE INNODB STATUS
---TRANSACTION 0, not started
MySQL thread id 2, OS thread handle 0x1560, query id 83 localhost 127.0.0.1 root cleaning up
--------
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
405 OS file reads, 168 OS file writes, 82 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.37 writes/s, 0.17 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
 insert 0, delete mark 0, delete 0
discarded operations:
 insert 0, delete mark 0, delete 0
Hash table size 58207, node heap has 0 buffer(s)
0.00 hash searches/s, 0.81 non-hash searches/s
---
LOG
---
Log sequence number 8995932
Log flushed up to   8995932
Pages flushed up to 8995932
Last checkpoint at  8995932
0 pending log writes, 0 pending chkp writes
43 log i/o's done, 0.08 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 30048256; in additional pool allocated 0
Dictionary memory allocated 55489
Buffer pool size   1792
Free buffers       1369
Database pages     423
Old database pages 0
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 391, created 32, written 97
0.00 reads/s, 0.08 creates/s, 0.21 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: 423, 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
0 read views open inside InnoDB
Main thread id 2672, state: sleeping
Number of rows inserted 0, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
=====================================
2013-05-26 13:07:32 460 INNODB监视器输出
=====================================
从最后52秒计算的平均每秒数
-----------------
背景线程
-----------------
srv_主线程循环:8个srv_活动,0个srv_关闭,7450个srv_空闲
srv_主线程日志刷新和写入:7458
----------
信号量
----------
OS等待阵列信息:保留计数20
OS等待阵列信息:信号计数19
互斥旋转等待2次,回合0次,操作系统等待0次
RW共享旋转19次,旋转570次,操作系统等待19次
RW excl旋转1次,旋转30次,操作系统等待1次
每次等待旋转轮数:0.00互斥,30.00 RW共享,30.00 RW不包括
------------------------
最新外键错误
------------------------
2013-05-26 13:07:16 foilmaster/contactdata表外键约束中的f0c错误:
引用表中没有包含的索引
列作为第一列,或中的数据类型
引用的表与表中的表不匹配。约束条件:
,
约束“ID”外键(“ID”)引用“公司”(“ID”)
表中外键的索引为“主”
看见http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html
获取正确的外键定义。
------------
交易
------------
Trx id计数器3386
清除trx的n:o<3386撤消n:o<0状态:运行但空闲
历史记录列表长度240
每个会话的事务列表:
---事务0,未启动
MySQL线程id 12,操作系统线程句柄0x460,查询id 394 localhost 127.0.0.1 root init
显示引擎INNODB状态
---事务0,未启动
MySQL线程id 2,操作系统线程句柄0x1560,查询id 83 localhost 127.0.0.1根目录清理
--------
文件I/O
--------
I/O线程0状态:等待Windows aio(插入缓冲区线程)
I/O线程1状态:等待Windows aio(日志线程)
I/O线程2状态:等待Windows aio(读取线程)
I/O线程3状态:等待Windows aio(读取线程)
I/O线程4状态:等待Windows aio(读取线程)
I/O线程5状态:等待Windows aio(读取线程)
I/O线程6状态:等待Windows aio(写入线程)
I/O线程7状态:等待Windows aio(写入线程)
I/O线程8状态:等待Windows aio(写入线程)
I/O线程9状态:等待Windows aio(写入线程)
挂起的正常aio读取:0[0,0,0,0],aio写入:0[0,0,0,0],
ibuf aio读取:0,日志i/o:0,同步i/o:0
挂起的刷新(fsync)日志:0;缓冲池:0
405个操作系统文件读取,168个操作系统文件写入,82个操作系统fsyncs
0.00读取/秒,0平均字节/读取,0.37写入/秒,0.17 fsyncs/s
-------------------------------------
插入缓冲区和自适应哈希索引
-------------------------------------
Ibuf:大小1,自由列表长度0,seg大小2,0个合并
合并操作:
插入0,删除标记0,删除0
丢弃的操作:
插入0,删除标记0,删除0
哈希表大小58207,节点堆有0个缓冲区
0.00哈希搜索/s,0.81非哈希搜索/s
---
日志
---
日志序列号8995932
日志刷新至8995932
页面刷新至8995932页
最后一个检查站8995932
0个挂起的日志写入,0个挂起的chkp写入
43日志i/o完成,0.08日志i/o/秒
----------------------
缓冲池和内存
----------------------
分配的总内存为30048256;在分配的其他池中0
字典内存分配55489
缓冲池大小1792
自由缓冲区1369
数据库第423页
旧数据库页0
已修改数据库第0页
挂起读取0
挂起写入:LRU 0,刷新列表0单页0
页面设置为年轻0,而不是年轻0
0.00扬格/秒,0.00非扬格/秒
阅读391页,创建32页,编写97页
0.00读取/秒,0.08创建/秒,0.21写入/秒
缓冲池命中率1000/1000,年轻制造率0/1000而非0/1000
页面预读0.00/s,无访问权收回0.00/s,随机预读0.00/s
LRU-len:423,解压_-LRU-len:0
I/O总和[0]:cur[0],解压总和[0]:cur[0]
--------------
行操作
--------------
InnoDB中有0个查询,队列中有0个查询
InnoDB内部打开0个读取视图
主线程id 2672,状态:休眠
插入的行数0,更新的行数0,删除的行数0,读取的行数0
0.00插入/秒、0.00更新/秒、0.00删除/秒、0.00读取/秒
----------------------------
INNODB监视器输出结束
============================

到目前为止花了2个小时。。。。只是盯着看:事实证明,两个答案都是错的。 解决办法是什么

我把这条线移到了顶端 如果存在表格
foilmaster
ContactData

此外,勾选下拉模式复选框也有效


我开始想为什么会是这样。。。最后的结局通常是“只要它起作用,我很好”:)

aargh!没有格式。。。请查看编辑帮助:失败的约束不在上面显示的脚本中。是否将列名从
ID
更改为
idCompany
?1。我刚刚使用了workbench gui creator,它有int1 int2 int3预设类型。所以我就用了那个-结果是mediumint(9)。
=====================================
2013-05-26 13:07:32 460 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 52 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 8 srv_active, 0 srv_shutdown, 7450 srv_idle
srv_master_thread log flush and writes: 7458
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 20
OS WAIT ARRAY INFO: signal count 19
Mutex spin waits 2, rounds 0, OS waits 0
RW-shared spins 19, rounds 570, OS waits 19
RW-excl spins 1, rounds 30, OS waits 1
Spin rounds per wait: 0.00 mutex, 30.00 RW-shared, 30.00 RW-excl
------------------------
LATEST FOREIGN KEY ERROR
------------------------
2013-05-26 13:07:16 f0c Error in foreign key constraint of table foilmaster/contactdata:
there is no index in referenced table which would contain
the columns as the first columns, or the data types in the
referenced table do not match the ones in table. Constraint:
,
  CONSTRAINT "ID" FOREIGN KEY ("ID") REFERENCES "company" ("ID")
The index in the foreign key in table is "PRIMARY"
See http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html
for correct foreign key definition.
------------
TRANSACTIONS
------------
Trx id counter 3386
Purge done for trx's n:o < 3386 undo n:o < 0 state: running but idle
History list length 240
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 12, OS thread handle 0x460, query id 394 localhost 127.0.0.1 root init
SHOW ENGINE INNODB STATUS
---TRANSACTION 0, not started
MySQL thread id 2, OS thread handle 0x1560, query id 83 localhost 127.0.0.1 root cleaning up
--------
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
405 OS file reads, 168 OS file writes, 82 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.37 writes/s, 0.17 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
 insert 0, delete mark 0, delete 0
discarded operations:
 insert 0, delete mark 0, delete 0
Hash table size 58207, node heap has 0 buffer(s)
0.00 hash searches/s, 0.81 non-hash searches/s
---
LOG
---
Log sequence number 8995932
Log flushed up to   8995932
Pages flushed up to 8995932
Last checkpoint at  8995932
0 pending log writes, 0 pending chkp writes
43 log i/o's done, 0.08 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 30048256; in additional pool allocated 0
Dictionary memory allocated 55489
Buffer pool size   1792
Free buffers       1369
Database pages     423
Old database pages 0
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 391, created 32, written 97
0.00 reads/s, 0.08 creates/s, 0.21 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: 423, 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
0 read views open inside InnoDB
Main thread id 2672, state: sleeping
Number of rows inserted 0, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================