2

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?

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • The problem is that postgresql hasn't named the constraint this way... – fge Jan 08 '12 at 17:36
  • Just a side note: I'm pretty sure you do *not* want `CHAR` but you want `VARCHAR` instead. –  Jan 09 '12 at 11:44

2 Answers2

1

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.

Lukáš Lalinský
  • 40,587
  • 6
  • 104
  • 126
0

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

Oleg Dok
  • 21,109
  • 4
  • 45
  • 54