1

I have a problem in mysql code. Not allow me to import sql file and give me this error " #1215 - Cannot add foreign key constraint "

I have no ideea what to do. I searched here, i tried some examples like this: MySQL error: Cannot add foreign key constraint? but no succes.

2
  • Why did you removed all the SQL code from your question? Now this question & answer is useless as it makes no sense. Commented Jun 14, 2015 at 21:04
  • it's code from my license... i dont want to be acused of plagiarism. Commented Jun 14, 2015 at 21:54

1 Answer 1

1

You need to use all of the primary key columns on your FK references.

FOREIGN KEY (`an`)
REFERENCES `studenti` (`an`) 

should be

FOREIGN KEY (`idstud`, `an`)
REFERENCES `studenti` (`idstud`,`an`) 

Of course, then you need to add idstud to your teste table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.