org.postgresql.util.PSQLException: ERROR: null value in column "parent_id" violates not-null constraint
I'd like to know since I have already made parent_id a primary key, do I need to put a idenity as ALWAYS and increment by 1 ?
cos another table I had used pgAdmin4 to define it as identity, ALWAYS, increment 1 and it works well....
so what is the difference between identity and PRIMARY KEY ?
and if I follow the other table definition for id and put in the ALWAYS, it will give me another problem...that the generated_id doesn't get inserted even though it should not
Hi Karen,
Please bottom post on this forum - it's uncommon these days, but the custom on this email list to post replies at the bottom of the email.
Regarding your question about nulls and primary keys -- yes you want to define, where it makes sense, to use autoincrementing primary keys, if you want the system to manage your keys. Note that autoincrementing IDs, if exposed to the public via the web or similar, could create some security issues.
But in many cases it makes a lot of sense to use them. To create a primary key that autoincrements, use the "serial" or "bigserial" datatype. Combined with a primary key (that enforces "not null" among other things), your create table would look like this:
CREATETABLE sample (idSERIALPRIMARYKEY,);
I have not tested it, but I'd guess you should be able to alter a table that has an integer primary key and convert it to a serial. I hope that's helpful! Steve