#how to lastinsert ID at postgres

18 messages · Page 1 of 1 (latest)

flint ridge
#

pq: null value in column "id" of relation "users" violates not-null constraint

shrewd gate
#

look at your table definition

#

and change the not null constraint as well as potentially use an auto increment value as key or a uuid.

#

problem is: database does not want null as a value in the id field (because table definition says so) but you insert a null value.

flint ridge
#

my defenition table

shrewd gate
#

so you try to create a user_detail

#

oh no

flint ridge
#

i want insert id to my users table

shrewd gate
#

might try something like this. you will need to drop or alter your table

#

in this case it's good to let the database generate the id.

#

because you do not provide an id field, the database says no

#

in order for the database to automatically create the id, you might need to tell it to do so

flint ridge
#

thankyouuu sir i will try it

#

this case the database definition bad not best practice the definition from sqlite now i want change to posgresql

#

in the postgresql autocrement need serial

#

tyy sirr for the insight