0

I just cant create the foreign key, I execute the SQL, it shows successfully in console, but, nothing happens

EDIT

SQL code

ALTER TABLE cotacaoitens
  ADD CONSTRAINT fk_cotacaoitens_cotacao
FOREIGN KEY (codigoconcentrador, codigoempresa, codigocotacao) REFERENCES cotacao (codigoconcentrador, codigoempresa, codigocotacao) ON DELETE CASCADE;

Successfull message

ALTER TABLE cotacaoitens
  ADD CONSTRAINT fk_cotacaoitens_cotacao
FOREIGN KEY (codigoconcentrador, codigoempresa, codigocotacao) REFERENCES cotacao (codigoconcentrador, codigoempresa, codigocotacao) ON DELETE CASCADE
[2018-01-03 15:27:04] completed in 110ms

enter image description here

Nico Haase
  • 11,420
  • 35
  • 43
  • 69
SpaceDogCS
  • 2,808
  • 3
  • 20
  • 49
  • 4
    Please post code, errors, sample data or textual output here as plain-text, not as images that can be hard to read, can’t be copy-pasted to help test code or use in answers, and are hostile to those who use screen readers. You can edit your question to add the code in the body of your question. Use the `{}` button to format any blocks of code, or indent with four spaces for the same effect. **We can’t run your screenshot as code.** – tadman Jan 03 '18 at 17:35
  • Sorry, i'm editing right now, i just don't know how to show the tables – SpaceDogCS Jan 03 '18 at 17:52
  • 1
    I contributed to a good checklist for foreign key errors in this question: https://stackoverflow.com/questions/1457305/mysql-creating-tables-with-foreign-keys-giving-errno-150 Please read through the checklist and see if any of them apply to your case. – Bill Karwin Jan 03 '18 at 17:54
  • I think thats the solution Bill, I changed the engine to MyISAM because I could not create the foreign key, one table was MyISAM and another was InnoDB, I'm going to change it, and if it works I comment – SpaceDogCS Jan 03 '18 at 18:00
  • Right, MyISAM doesn't support foreign keys, but it won't give an error either. It just ignores the request to create the foreign key. It says, "La la la I'm not listening" and puts its fingers in its ears. – Bill Karwin Jan 03 '18 at 18:33

1 Answers1

1

MyISAM doesn't support foreign keys, but it won't give an error either. It just ignores the request to create the foreign key. It says, "La la la I'm not listening" and puts its fingers in its ears.

I contributed to a good checklist for foreign key errors in this question: MySQL Creating tables with Foreign Keys giving errno: 150 Please read through the checklist and see if any of them apply to your case.

Bill Karwin

SpaceDogCS
  • 2,808
  • 3
  • 20
  • 49