I have a table which has a primary key column "gid" and its type is "Integer NOT NULL". I want to convert it into "Serial NOT NULL" so that I can insert some values into this table. I used following commands to convert it into serial:
CREATE SEQUENCE test_table_gid_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 2147483648 START 1
CACHE 1;
ALTER TABLE test_table ALTER COLUMN gid
SET DEFAULT nextval('test_table_gid_seq'::regclass);
This command converted integer to serial. But while I entered some data to the table following error occurred:
ERROR: duplicate key value violates unique constraint "pk_test".
Please help me to solve this. Is there any other method to convert integer to serial?