I have a table with only one Field ID type Serial Autonumeric and is a PK, i want insert a new record but it show me error Not null violation, but if i put a value the first INSERT work correctly but the next Insert it Show me error Unique violation,
So i try adding a new field in this table and put a value null to this field, and the ID Autonumeric work .
Exist a way to do it only with a field, i'm working with PHP???
Some actual examples form you end would help:)
My guess is you are trying to insert a NULL value into the PK field instead of just not inserting anything at all. An alternative is to use the DEFAULT keyword. See below for example.
create table test_table(id_fld serial primary key, char_fld varchar);
test=> \d test_table Table "public.test_table" Column | Type | Modifiers ----------+-------------------+------------------------------------------------------------- id_fld | integer | not null default nextval('test_table_id_fld_seq'::regclass) char_fld | character varying | Indexes: "test_table_pkey" PRIMARY KEY, btree (id_fld)
test=> INSERT INTO test_table (id_fld , char_fld) VALUES (NULL, 't'); ERROR: null value in column "id_fld" violates not-null constraint
test=> INSERT INTO test_table (char_fld) VALUES ('t'); INSERT 0 1