...
What probably could also help: If there is a key on the foreign table affecting the field to be used as foreign key: recreate that index. (Not tested)
...
Solutions for case 2:
Solution A - inconsistent data types / collations / encodings
See https://stackoverflow.com/questions/16969060/mysql-error-1215-cannot-add-foreign-key-constraint
One example to get the error:
- Livesystem DB System or DB itself is using encoding and/or collation A as default
- Testsystem DB System or DB itself is using encoding and/or collation B as default
- User makes a dump from live and applies it to Testsystem
- User then tries to update the Testsystem
- The dump from live creates table LEK_task with encoding/collation A
- The Update tries to create table XYZ with collation B
- => Result: the foreign key could not be created
Solution B - innoDB foreign keys corrupt
In that case the error happened on Updating data in the LEK_term_attributes table. Error was:
...