外键导致mysql中的主键重复输入

时间:2019-06-01 07:21:33

标签: mysql

我有一个名为:rental

的表
id_customer_re|id_dvd_re|date_of_rental
1             1         2019-03-04
2             2         2019-02-05
3             3         2019-01-03
4             4         2019-01-10
5             5         2019-01-02
1             1         2019-03-05
1             3         2019-03-23
1             4         2019-03-23
1             3         2019-03-12
2             3         2019-03-23
2             1         2019-03-11

我手动填充了这些行,并且出现此错误。

我在网站上找到了许多与此相关的信息,但问题是我已将前两列转为外国键,但仍然存在相同的错误。

所以我真的不知道如何填充这些记录,因为重要的是要拥有多次正常发生的这些客户的购买数据。我能做什么?谢谢

CREATE TABLE `dvd_club`.`customer` (

  `id_customer` VARCHAR(20) NOT NULL,

  `name_cust` VARCHAR(50) NOT NULL,

  `surname_cust` VARCHAR(50) NOT NULL,

  `date_of_birth_cust` DATE NULL,

  `id_customer_store` VARCHAR(20) NOT NULL,

  PRIMARY KEY (`id_customer`),

  INDEX `id_customer_store_idx` (`id_customer_store` ASC) VISIBLE,

  CONSTRAINT `id_customer_store`

    FOREIGN KEY (`id_customer_store`)

    REFERENCES `dvd_club`.`store` (`id_store`)

    ON DELETE NO ACTION

    ON UPDATE NO ACTION);







CREATE TABLE `dvd_club`.`dvd` (

  `id_dvd` VARCHAR(20) NOT NULL,

  `genre` VARCHAR(50) NULL,

  `release_date` YEAR(4) NULL,

  `string_per_title` VARCHAR(50) NULL,

  `id_dvd_customer` VARCHAR(20) NOT NULL,

  PRIMARY KEY (`id_dvd`),

  INDEX `id_dvd_customer_idx` (`id_dvd_customer` ASC) VISIBLE,

  CONSTRAINT `id_dvd_customer`

    FOREIGN KEY (`id_dvd_customer`)

    REFERENCES `dvd_club`.`customer` (`id_customer`)

    ON DELETE NO ACTION

    ON UPDATE NO ACTION);





    CREATE TABLE `dvd_club`.`rental` (

      `id_customer_re` VARCHAR(20) NOT NULL,

      `id_dvd_re` VARCHAR(20) NOT NULL,

      `date_of_rental` DATE NULL,

      `date_of_delivery` DATE NULL,

      PRIMARY KEY (`id_customer_re`, `id_dvd_re`),

      INDEX `id_dvd_re_idx` (`id_dvd_re` ASC) VISIBLE,

      CONSTRAINT `id_customer_re`

        FOREIGN KEY (`id_customer_re`)

    REFERENCES `dvd_club`.`customer` (`id_customer`)

        ON DELETE NO ACTION

        ON UPDATE NO ACTION,

      CONSTRAINT `id_dvd_re`

        FOREIGN KEY (`id_dvd_re`)

        REFERENCES `dvd_club`.`dvd` (`id_dvd`)

        ON DELETE NO ACTION

        ON UPDATE NO ACTION);

0 个答案:

没有答案