外键约束错误 1005 erno 121

外键约束错误 1005 erno 121

我绞尽脑汁想要创建这个表。在具有类似约束的 mariadb 10 中,其他表也可以正常创建。我已经通过调试器运行它,但没有成功。

ERROR 1005 (HY000) at line 401 in file: '/usr/share/doc/dbmail/examples/create_tables.mysql': Can't create table `dbmail`.`dbmail_auto_replies` (errno: 121 "Duplicate key on write or update")

DROP TABLE IF EXISTS `dbmail_users`;
CREATE TABLE `dbmail_users` ( 
   `user_idnr` bigint(20) UNSIGNED NOT NULL auto_increment, 
   `userid` varchar(255) NOT NULL default '',
   `passwd` varchar(255) NOT NULL default '',
   `client_idnr` bigint(20) UNSIGNED NOT NULL default '0',
   `maxmail_size` bigint(20) NOT NULL default '0',
   `curmail_size` bigint(20) NOT NULL default '0',
   `maxsieve_size` bigint(20) NOT NULL default '0',
   `cursieve_size` bigint(20) NOT NULL default '0',
   `encryption_type` varchar(255) NOT NULL default '',
   `last_login` datetime NOT NULL default '1979-11-03 22:05:58',
   PRIMARY KEY  (`user_idnr`),
   UNIQUE KEY `userid_index` (`userid`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS dbmail_auto_notifications;                        CREATE TABLE dbmail_auto_notifications (
        user_idnr bigint(20) UNSIGNED NOT NULL,
        notify_address varchar(100) NOT NULL default '',
        INDEX user_idnr_index (user_idnr),
        FOREIGN KEY user_idnr_fk (user_idnr)
                REFERENCES dbmail_users (user_idnr) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS dbmail_auto_replies; CREATE TABLE dbmail_auto_replies (
        user_idnr bigint(20) UNSIGNED DEFAULT '0' NOT NULL,
        start_date DATETIME NOT NULL,
        stop_date DATETIME NOT NULL,
        reply_body MEDIUMTEXT,
        INDEX user_idnr_index (user_idnr),
        FOREIGN KEY user_idnr_fk (user_idnr)
                REFERENCES dbmail_users (user_idnr) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE InnoDB DEFAULT CHARSET=utf8;

任何帮助是极大的赞赏。

答案1

尝试对外键使用不同的名称,两种情况下都有 user_idnr_fk。当我更改名称时,表就创建了。

相关内容