15.04.2014, 15:42
(
Последний раз редактировалось Mellnik; 16.04.2014 в 14:34.
)
I've tried your table design and connected several tables with the accounts table. But sometimes following error comes up:
Any idea, Vince? :/
Edit: Found the problem, the query tried to insert into `achievements` using a index key not available in `accounts`.
Код:
[ERROR] CMySQLQuery::Execute[] - (error #1452) Cannot add or update a child row: a foreign key constraint fails (`nefserver`.`achievements`, CONSTRAINT `achievements_ibfk_1` FOREIGN KEY (`id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)
Код:
CREATE TABLE IF NOT EXISTS `accounts` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(24) NOT NULL, other stuff here, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=45802 ; CREATE TABLE IF NOT EXISTS `achievements` ( `id` int(10) unsigned NOT NULL, `type` tinyint(3) unsigned NOT NULL, `unlockdate` int(10) unsigned NOT NULL, KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Constraints for table `achievements` -- ALTER TABLE `achievements` ADD CONSTRAINT `achievements_ibfk_1` FOREIGN KEY (`id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Edit: Found the problem, the query tried to insert into `achievements` using a index key not available in `accounts`.