2
I want to connect the 2 FK of the credit card table and bank bill to the Id_payment table plus the following error arises:
Error Code: 1022. Can’t 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;

What exactly is the error command? You can add the command to create FK?
– Murillo Goulart
15:29:47 ALTER TABLE
prestadora.cartao_creditoADD CONSTRAINTPagamentoID_PagamentoFOREIGN KEY (PagamentoID_Pagamento) REFERENCESprestadora.pagamento(ID_Pagamento) ON DELETE NO ACTION ON UPDATE NO ACTION Error Code: 1022. Can’t write; Duplicate key in table '#sql-900_e' 0.141 sec– user63891
and I did the same in the boleto table and it worked
– user63891
But did you put the exact same name on CONSTRAINT? This could be the problem.
– jlHertel
and why it would be already that this referring to the same table ?
– user63891
ALTER TABLE
prestadora.boleto_bancarioADD CONSTRAINTPagamentoID_PagamentoFOREIGN KEY (PagamentoID_Pagamento) REFERENCESprestadora.pagamento(ID_Pagamento) ON DELETE NO ACTION ON UPDATE NO ACTION;– user63891