@101010101010

Почему не создается таблица с FOREIGN KEY?

Не создаётся таблица item .
Без FOREIGN KEY всё создаётся.
Ошибка Error code 1005, SQL state HY000: Can't create table 'zimaip.item' (errno: 150).
Все таблицы InnoDB.

CREATE TABLE org (
org_id INT not null primary key auto_increment ,
identifier VARCHAR ( 25 ) not null UNIQUE
)DEFAULT CHARSET=utf8;

CREATE TABLE person (
p_id INT not null auto_increment primary key , 
p_name VARCHAR ( 25 ) not null ,
p_login VARCHAR ( 15 ) not null ,
password VARCHAR ( 15 ) not null , 
org INT not null ,
FOREIGN  KEY ( org ) REFERENCES org ( org_id )
ON UPDATE CASCADE 
ON DELETE CASCADE ,
UNIQUE ( p_login , password , org  ) 
)DEFAULT CHARSET=utf8;


CREATE TABLE item (
i_id INT not null auto_increment primary key , 
i_norm FLOAT not null,
i_sum FLOAT not null,
i_tarif1 FLOAT not null,
i_service INT not null, 
i_person INT not null, 
FOREIGN  KEY ( i_person ) REFERENCES persone ( p_id )
ON UPDATE CASCADE
ON DELETE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=utf8;


show innodb status выдал
=====================================
140323 20:26:19 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 17 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 236 1_second, 236 sleeps, 12 10_second, 119 background, 119 flush
srv_master_thread log flush and writes: 238
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 16, signal count 16
Mutex spin waits 3, rounds 61, OS waits 0
RW-shared spins 16, rounds 480, OS waits 16
RW-excl spins 0, rounds 0, OS waits 0
Spin rounds per wait: 20.33 mutex, 30.00 RW-shared, 0.00 RW-excl
------------------------
LATEST FOREIGN KEY ERROR
------------------------
140323 20:24:50 Error in foreign key constraint of table zimaip/item:
FOREIGN KEY ( i_person ) REFERENCES persone ( p_id )
ON UPDATE CASCADE
ON DELETE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=utf8:
Cannot resolve table name close to:
( p_id )
ON UPDATE CASCADE
ON DELETE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=utf8
------------
TRANSACTIONS
------------
Trx id counter 177B
Purge done for trx's n:o < 1775 undo n:o < 0
History list length 17
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 173C, not started
MySQL thread id 3, OS thread handle 0xc3c, query id 802 localhost 127.0.0.1 root
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
214 OS file reads, 216 OS file writes, 68 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 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 69257, node heap has 1 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 1756843
Log flushed up to 1756843
Last checkpoint at 1756843
0 pending log writes, 0 pending chkp writes
39 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 17006592; in additional pool allocated 0
Dictionary memory allocated 25843
Buffer pool size 1024
Free buffers 807
Database pages 216
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 203, created 13, written 166
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 216, 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 1704, state: waiting for server activity
Number of rows inserted 1, updated 0, deleted 0, read 183
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================


Помогите, пожалуйста, разобраться.
  • Вопрос задан
  • 2678 просмотров
Решения вопроса 1
FFxSquall
@FFxSquall
Могу писать код, могу не писать
Может всё же правильно REFERENCES person, а не persone =)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы