Error message when dropping constrain

466 views Asked by At

Every time I want to drop a constraint from a column I get an error. I can't see the problem. I am using postgres.

So I have created a table with two columns:

CREATE TABLE TableA(
person_id INT PRIMARY KEY,
lastname CHAR(100)
)

I use the code

ALTER TABLE TableA DROP CONSTRAINT person_id

to DROP the constraint from person_id but then I get an error:

Error : ERROR:  constraint "person_id" of relation "tablea" does not exist

What's the problem?

2

There are 2 answers

0
Lukáš Lalinský On BEST ANSWER

Primary keys in PostgreSQL are by default called <table>_pkey, so you probably want something like this:

ALTER TABLE TableA DROP CONSTRAINT TableA_pkey;

You can check the names for example in psql using \d TableA.

0
Oleg Dok On

That means that you choose wrong name of constraint - you choose column name instead of constraint