New question

Question:

Date: 12-02-2020 09:03:24 (In Spanish)

No puedo crear tabla `bomgos`.`report_product` (Error: 121 "Duplicate key on write or update")[Resolved]

Hola amigos de la comunidad, estoy creando una base de datos y resulta que me sale un error que desconozco en la tabla report_product y no conozco la causa del error.

[url=https://ibb.co/0tLby1d][/url]

Código de la base de datos:
CREATE DATABASE bomgos;
USE bomgos;

CREATE TABLE users(
id_usuario      int(255) AUTO_INCREMENT PRIMARY KEY,
name            varchar(100) not null,
surname         varchar(100) not null,
email           varchar(100) UNIQUE not null,
password        varchar(255) not null,
description     text,
photo_perfil    varchar(200),
photo_portada   varchar(200),
telephone       varchar(50),
sexo            varchar(50) not null,
day             varchar(20) not null,
month           varchar(30) not null,
year            varchar(20) not null,
create_at_user  date
)ENGINE=InnoDb;

CREATE TABLE product(
id_producto         int(255) AUTO_INCREMENT PRIMARY KEY,
user_id             int(255) not null,
title               varchar(200) not null,
description         text not null,
moneda              varchar(100) not null,
price               varchar(200) not null,
ubication           varchar(150) not null,
video               varchar(255),
miniatura           varchar(255),
images_uno          varchar(255) not null,
images_dos          varchar(255),
images_tres         varchar(255),
images_cuatro       varchar(255),
images_cinco        varchar(255),
images_seis         varchar(255),
category            varchar(255) not null,
condicion           varchar(50) not null,
state               varchar(100),
create_at_comment   date,
CONSTRAINT fk_product_users FOREIGN KEY(user_id) REFERENCES users(id_usuario)
)ENGINE=InnoDb;

CREATE TABLE comment(
id_comment          int(255) AUTO_INCREMENT PRIMARY KEY,
user_id             int(255) not null,
product_id          int(255) not null,
images_comment      varchar(255),
comments            text not null,
create_at_comment   date,
CONSTRAINT fk_comment_user FOREIGN KEY(user_id) REFERENCES users(id_usuario ),
CONSTRAINT fk_comment_product FOREIGN KEY(product_id) REFERENCES product(id_producto)
)ENGINE=InnoDb;

CREATE TABLE chat(
id_chat         int(255) AUTO_INCREMENT PRIMARY KEY,
user_id         int(255) not null,
product_id      int(255) not null,
images_chat     varchar(255),
chat            text not null,
create_at_chat  date not null,
CONSTRAINT fk_chat_user FOREIGN KEY(user_id) REFERENCES users(id_usuario),
CONSTRAINT fk_chat_product FOREIGN KEY(product_id) REFERENCES product(id_producto)
)ENGINE=InnoDb;

CREATE TABLE report_comment(
id_report_comment           int(255) AUTO_INCREMENT PRIMARY KEY,
user_id                     int(255) not null,
comment_id                  int(255) not null,
product_id                  int(255) not null,
motivo                      varchar(200) not null,
detail                      text not null,
create_at_report_comment    date not null,
CONSTRAINT fk_report_comment_user FOREIGN KEY(user_id) REFERENCES users(id_usuario),
CONSTRAINT fk_report_product_id FOREIGN KEY(product_id) REFERENCES product(id_producto),
CONSTRAINT fk_report_comment_id FOREIGN KEY(comment_id) REFERENCES comment(id_comment)
)ENGINE=InnoDb;

CREATE TABLE report_product(
id_report_product           int(255) AUTO_INCREMENT PRIMARY KEY,
user_id                     int(255) not null,
product_id                  int(255) not null,
motivo                      varchar(200) not null,
detail                      text not null,
create_at_report_product    date not null,
CONSTRAINT fk_report_product_user FOREIGN KEY(user_id) REFERENCES users(id_usuario),
CONSTRAINT fk_report_product_id FOREIGN KEY(product_id) REFERENCES product(id_producto)
)ENGINE=InnoDb;
Tags: MySQL - PHP - PHP MySQLi - SQL Votes: -1 - Answers: 1 - Views: 2 Share on: Google Facebook Twitter LinkedIn Link
 

Answers:

  • Date: 12-02-2020 09:11:36 Ya he logrado solucionar el error 121, el problema es que estaba llamando a 2 CONTRAINT de la misma manera, solo tuve que editar el nombre de uno de los dos.

    Este problema ya esta resuelto.
    Aquí esta el código ya resuelto:
    CREATE DATABASE bomgos;
    USE bomgos;
    
    CREATE TABLE users(
    id_usuario      int(255) AUTO_INCREMENT PRIMARY KEY,
    name            varchar(100) not null,
    surname         varchar(100) not null,
    email           varchar(100) UNIQUE not null,
    password        varchar(255) not null,
    description     text,
    photo_perfil    varchar(200),
    photo_portada   varchar(200),
    telephone       varchar(50),
    sexo            varchar(50) not null,
    day             varchar(20) not null,
    month           varchar(30) not null,
    year            varchar(20) not null,
    create_at_user  date
    )ENGINE=InnoDb;
    
    CREATE TABLE product(
    id_producto         int(255) AUTO_INCREMENT PRIMARY KEY,
    user_id             int(255) not null,
    title               varchar(200) not null,
    description         text not null,
    moneda              varchar(100) not null,
    price               varchar(200) not null,
    ubication           varchar(150) not null,
    video               varchar(255),
    miniatura           varchar(255),
    images_uno          varchar(255) not null,
    images_dos          varchar(255),
    images_tres         varchar(255),
    images_cuatro       varchar(255),
    images_cinco        varchar(255),
    images_seis         varchar(255),
    category            varchar(255) not null,
    condicion           varchar(50) not null,
    state               varchar(100),
    create_at_comment   date,
    CONSTRAINT fk_product_users FOREIGN KEY(user_id) REFERENCES users(id_usuario)
    )ENGINE=InnoDb;
    
    CREATE TABLE comment(
    id_comment          int(255) AUTO_INCREMENT PRIMARY KEY,
    user_id             int(255) not null,
    product_id          int(255) not null,
    images_comment      varchar(255),
    comments            text not null,
    create_at_comment   date,
    CONSTRAINT fk_comment_user FOREIGN KEY(user_id) REFERENCES users(id_usuario ),
    CONSTRAINT fk_comment_product FOREIGN KEY(product_id) REFERENCES product(id_producto)
    )ENGINE=InnoDb;
    
    CREATE TABLE chat(
    id_chat         int(255) AUTO_INCREMENT PRIMARY KEY,
    user_id         int(255) not null,
    product_id      int(255) not null,
    images_chat     varchar(255),
    chat            text not null,
    create_at_chat  date not null,
    CONSTRAINT fk_chat_user FOREIGN KEY(user_id) REFERENCES users(id_usuario),
    CONSTRAINT fk_chat_product FOREIGN KEY(product_id) REFERENCES product(id_producto)
    )ENGINE=InnoDb;
    
    CREATE TABLE report_comment(
    id_report_comment           int(255) AUTO_INCREMENT PRIMARY KEY,
    user_id                     int(255) not null,
    comment_id                  int(255) not null,
    product_id                  int(255) not null,
    motivo                      varchar(200) not null,
    detail                      text not null,
    create_at_report_comment    date not null,
    CONSTRAINT fk_report_comment_user FOREIGN KEY(user_id) REFERENCES users(id_usuario),
    CONSTRAINT fk_report_id_product FOREIGN KEY(product_id) REFERENCES product(id_producto),
    CONSTRAINT fk_report_comment_id FOREIGN KEY(comment_id) REFERENCES comment(id_comment)
    )ENGINE=InnoDb;
    
    CREATE TABLE report_product(
    id_report_product           int(255) AUTO_INCREMENT PRIMARY KEY,
    user_id                     int(255) not null,
    product_id                  int(255) not null,
    motivo                      varchar(200) not null,
    detail                      text not null,
    create_at_report_product    date not null,
    CONSTRAINT fk_report_product_user FOREIGN KEY(user_id) REFERENCES users(id_usuario),
    CONSTRAINT fk_report_product_id FOREIGN KEY(product_id) REFERENCES product(id_producto)
    )ENGINE=InnoDb;
      Votes: 0 - Link answer
     
To actively participate in the community first must authenticate, enter the system.Sign In