1
I tried to use the DROP CASCADE
and ALTER TABLE <nome_tabela> DROP FOREIGN KEY <chave_estrangeira>, DROP KEY <chave_estrangeira>
to delete a table with foreign keys in MYSQL, but it does not work.
CREATE TABLE forma_pagamento (
cd_forma_pagamento INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
tipo_pagamento VARCHAR(30),
CHECK (tipo_pagamento IN ('Pagamento á vista'))
);
-- Quero apagar a tebela pagamento, mas a chave da tabela forma_pagamento não permite
CREATE TABLE pagamento (
cd_pagamento INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
cd_forma_pagamento INT,
FOREIGN KEY (cd_forma_pagamento) REFERENCES forma_pagamento (cd_forma_pagamento)
);
What error is appearing? Because you should first delete the foreign keys and then delete the table
alter table pagamento drop foreign key cd_forma_pagamento
– Erlon Charles
Error Code: 1091. Can't DROP FOREIGN KEY `cd_forma_pagamento`; check that it exists

– user184985
Are you saying that this foreign key does not exist, which error gives when you try to delete the table?
– Erlon Charles
Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails
– user184985
This question may contain the answer you are looking for https://answall.com/questions/67510/erro-ao-deletar-fk
– Erlon Charles
This answers your question? Error while deleting FK
– Brewerton Santos