错误:外键约束名称重复

时间:2019-01-16 06:50:30

标签: python django django-models django-forms django-rest-framework

我从工作台中导出了一个架构,现在尝试使用该脚本在服务器中创建表,但是会出错

我尝试更改表,还尝试查找重复的foriegn键。

错误1826:重复的外键约束名称“ bank_id” SQL语句:


-表adityausers_has_bank


CREATE TABLE IF NOT EXISTS `aditya`.`users_has_bank` (
  `users_user_id` INT NOT NULL AUTO_INCREMENT,
  `bank_id` INT NOT NULL,
  `user_id` INT NOT NULL,
  PRIMARY KEY (`users_user_id`),
  INDEX `bank_id_idx` (`bank_id` ASC) VISIBLE,
  INDEX `user_id_idx` (`user_id` ASC) VISIBLE,
  CONSTRAINT `bank_id`
    FOREIGN KEY (`bank_id`)
    REFERENCES `aditya`.`bank` (`bank_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_id`
    FOREIGN KEY (`user_id`)
    REFERENCES `aditya`.`users` (`user_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB

1 个答案:

答案 0 :(得分:0)

在您的架构中的其他表中使用FK名称的可能性很高。请练习良好的FK命名约定

来源:Foreign Key naming scheme