Reputation: 896
Postgresql primary key not auto incrementing even when notation serial specified this is my table create script
CREATE TABLE public."Medication" (
"Id" serial NOT NULL,
"ResidentId" int4 NOT NULL,
"PharmacyId" int4 NULL,
"PhysicianId" int4 NULL,
"ReleasedQty" float8 NOT NULL DEFAULT '0'::double precision,
"PRNEffectiveTime" int4 NULL,
"IsSTO" bool NOT NULL DEFAULT false,
"IsPendingOrder" bool NOT NULL DEFAULT false,
"IsPsychotropic" bool NOT NULL DEFAULT false,
"IsINRRequired" bool NOT NULL DEFAULT false,
"eSignature" varchar NULL,
"eSignatureDate" timestamp NULL,
"PhysicianId_X" int4 NULL,
"IsWitnessSigReq" bool NULL,
"IsInjection" bool NULL,
"AdministerByRole" varchar NULL,
"AdministerByUser" varchar NULL,
"AlfId" int4 NOT NULL,
CONSTRAINT "Medication_pkey" PRIMARY KEY ("Id", "AlfId")
)
PARTITION BY RANGE ("AlfId");
the value of Id always remains zero
Upvotes: 1
Views: 364
Reputation: 896
My query was inserting explicit value 0 and this was happening in .net core with Medication Object containing Id zero. when in my class I specified Id as Identity column then it fixed
Table("Medication")]
public partial class Medication
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
I was not adding [DatabaseGenerated(DatabaseGeneratedOption.Identity)] and this is why it was happening
Upvotes: 2