Skip to content
Advertisement

MySQL error: Cannot add foreign key constraint (PrestaShop module)

I’m trying to write MySQL queries for my custom PrestaShop module. I encountered an issue while adding foreign keys and have no idea what might be wrong. I double checked column types and their existance.

Here’s the error:

Cannot add foreign key constraint

And here is all the code I’m trying to run during installation

The queries execute perfectly without foreign keys.

UPDATE

Found out that the issue is this line:

However, I haven’t yet figured out how to fix it.

Advertisement

Answer

I found the solution to the problem.

In the table ps_product column id_product is UNSIGNED and NOT NULL.

While creating table ps_pp_project I create column id_product without specifying those attributes

To solve the issue, the query should look like this:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement