Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top