эта вставка не работает в моей базе данных -
insert into tig_pairs (pkey, pval, uid) select 'schema-version', '4.0', uid from tig_users where (sha1_user_id = sha1(lower('db-properties')));
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`tigasedb`.`tig_pairs`, CONSTRAINT `tig_pairs_constr_2` FOREIGN KEY (`nid`) REFERENCES `tig_nodes` (`nid`))
Где определения таблиц:
create table if not exists tig_pairs (
nid int unsigned,
uid int unsigned NOT NULL,
pkey varchar(255) NOT NULL,
pval mediumtext,
PRIMARY KEY (nid, pkey), -- ***
key pkey (pkey),
key uid (uid),
key nid (nid),
constraint tig_pairs_constr_1 foreign key (uid) references tig_users (uid),
constraint tig_pairs_constr_2 foreign key (nid) references tig_nodes (nid)
)
ENGINE=InnoDB default character set utf8 ROW_FORMAT=DYNAMIC;
а также
create table if not exists tig_nodes (
nid int unsigned NOT NULL auto_increment,
parent_nid int unsigned,
uid int unsigned NOT NULL,
node varchar(255) NOT NULL,
primary key (nid),
unique key tnode (parent_nid, uid, node),
key node (node),
key uid (uid),
key parent_nid (parent_nid),
constraint tig_nodes_constr foreign key (uid) references tig_users (uid)
)
ENGINE=InnoDB default character set utf8 ROW_FORMAT=DYNAMIC;
Строка PRIMARY KEY (nid, pkey), -- ***
пропущена, тогда мой запрос проходит нормально. Есть ли конфликт между этим первичным ключом и тревожным ограничением внешнего ключа? Как я могу этого избежать? Первичный ключ должен оставаться там :)
Спасибо!
EDIT: избавился от ошибки, изменив определение tig_pairs в одной строке:
nid int unsigned NOT NULL auto_increment,