Skip to content
Advertisement

Failed to add the foreign key constraint. Missing index for constraint ‘information_ibfk_1’ in the referenced table ‘informacia’

What is the problem with these tables?

I want to create foreign key for second one

Advertisement

Answer

In order for a table to add a foreign key constraint, the referenced column (zip_code in this case) must be a PRIMARY KEY or must have a UNIQUE constraint (ideally with NOT NULL).

I modified the SQL statements according to PostgreSQL database. You don’t mention the specific database and PostgreSQL implements a highly standard SQL. The script, modified with two changes, is:

See running example at DB Fiddle.

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