2 FK for a 1 PK

2

I want to connect the 2 FK of the credit card and bank slip table to the payment table of the Payment ID plus the following error appears:

  

Error Code: 1022. Can not write; duplicate key in table '# sql-900_e'

I have no idea how it will solve, any help I appreciate

CREATE TABLE 'cartao_credito' (
  'ID_Cartao' int(100) NOT NULL AUTO_INCREMENT,
  'Numero_Cartao' varchar(50) DEFAULT NULL,
  'Codigo_Seguranca' varchar(50) DEFAULT NULL,
  'Nome_Titular' varchar(50) DEFAULT NULL,
  'Validade_Mes' varchar(50) DEFAULT NULL,
  'Validade_Ano' varchar(50) DEFAULT NULL,
  'PagamentoID_Pagamento' int(100) NOT NULL,
  PRIMARY KEY ('ID_Cartao'),
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE 'boleto_bancario' (
  'ID_Boleto' int(100) NOT NULL AUTO_INCREMENT,
  'Cedente' varchar(50) DEFAULT NULL,
  'Agencia_Codigo' varchar(50) DEFAULT NULL,
  'Numero_Documento' varchar(50) DEFAULT NULL,
  'CPF_CNPJ' varchar(50) DEFAULT NULL,
  'Valor_Documento' varchar(50) DEFAULT NULL,
  'Codigo_Boleto' varchar(50) DEFAULT NULL,
  'Codigo_Banco' varchar(50) DEFAULT NULL,
  'Data_Vencimento' varchar(50) DEFAULT NULL,
  'Data_Documento' varchar(50) DEFAULT NULL,
  'N_Documento' varchar(50) DEFAULT NULL,
  'Nosso_Numero' varchar(50) DEFAULT NULL,
  'PagamentoID_Pagamento' int(100) NOT NULL,
  PRIMARY KEY ('ID_Boleto'),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE 'pagamento' (
  'ID_Pagamento' int(100) NOT NULL AUTO_INCREMENT,
  'Tipo_Pagamento' int(10) DEFAULT NULL,
  'PedidoID_Pedido' int(100) NOT NULL,
  'Agenda_ServicoID_Agenda' int(10) NOT NULL,
  PRIMARY KEY ('ID_Pagamento'),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
asked by anonymous 14.02.2017 / 18:44

1 answer

2

Try changing the name of the constraint, as follows:

ALTER TABLE prestadora.cartao_credito ADD CONSTRAINT FK_Pagamento 
FOREIGN KEY(PagamentoID_Pagamento) REFERENCES prestadora.pagamento (ID_Pagamento) 
ON DELETE NO ACTION ON UPDATE NO ACTION

According to documentation , the constraint identifier must be unique, otherwise an error will be generated similar to:

ERROR 1022 (2300): Can't write; duplicate key in table '#sql- 464_1'

Optionally the name can be omitted, being generated automatically by the bank.

    
14.02.2017 / 19:31