It seems you want to remove the restriction only if it exists.
In Postgres, you can use:
ALTER TABLE custom_table
DROP CONSTRAINT IF EXISTS fk_states_list;
You can also verify that the table exists:
ALTER TABLE IF EXISTS custom_table
DROP CONSTRAINT IF EXISTS fk_states_list;
source
share