I’m working with PostgreSQL 9.1.
In psql I’m using this query to discover what constraints I have in a certain DB…
SELECT
*
FROM
information_schema.constraint_table_usage
WHERE
constraint_table_usage.table_catalog = 'journal_app_development'
AND
constraint_table_usage.constraint_name NOT LIKE '%_pkey';
Output…
table_catalog | table_schema | table_name | constraint_catalog | constraint_schema | constraint_name
-------------------------+--------------+------------+-------------------------+-------------------+-----------------
journal_app_development | public | users | journal_app_development | public | fk_entry_user
journal_app_development | public | users | journal_app_development | public | fk_user_task
(2 rows)
But when I try to drop a constraint I get an error…
# ALTER TABLE users DROP CONSTRAINT "fk_entry_user";
ERROR: constraint "fk_entry_user" of relation "users" does not exist
Any idea what I’m doing wrong?
Background info / motivation
The reason I’m doing this is that I want to write a script (specifically a Rake task) that will drop constraints in the DB that aren’t primary keys.
Try looking at the table:
where the
constraint_typecolumn <> ‘PRIMARY KEY’. I believe that should give you the other side of the relationship.I believe you are trying to drop the constraint from the referenced table, not the one that owns it.