lumber icon indicating copy to clipboard operation
lumber copied to clipboard

[+] Default Values - Lumber should generate the models based on the columns default values

Open prevostc opened this issue 5 years ago • 4 comments

I have Postgres 10 instance with a keyword table with an uuid column like this:

CREATE TABLE "keyword" (
            "uuid" "uuid" DEFAULT "public"."uuid_generate_v4"() PRIMARY KEY,
            "createdDate" timestamp without time zone NOT NULL DEFAULT now(), 
            "updatedDate" timestamp without time zone NOT NULL DEFAULT now(),
            "name" varchar(250) NOT NULL, 
            "language" varchar NOT NULL, 
            "status" varchar NOT NULL DEFAULT ('CREATED')
 )

When I try to create a new entity from the interface, there is this error: null value in column "uuid" violates not-null constraint.

Setting defaultValue: Sequelize.literal('uuid_generate_v4()'), fixes it.

prevostc avatar Aug 06 '18 16:08 prevostc

Thank you @prevostc for the valuable feedback. Happy you managed to find the workaround by yourself!

I cannot provide any ETA for such improvement but we now have it in mind.

arnaudbesnier avatar Aug 23 '18 07:08 arnaudbesnier

is this still a problem? Is there a way to fix it?

p0wl avatar Mar 09 '20 23:03 p0wl

Hi @p0wl, if you encounter the same issue, I guess it is still a problem. Is that what you observe?

A workaround is described in the issue description: you'll have to edit manually the model fields definitions with the right default value declaration.

arnaudbesnier avatar Mar 10 '20 07:03 arnaudbesnier

Hey, sorry for the unspecific comment. Yes, the issue with non-null default values is still present. My table definition looks like this:

CREATE TABLE public.something
(
    id uuid NOT NULL DEFAULT uuid_generate_v4(),
    "number" integer NOT NULL,
    name character(255) COLLATE pg_catalog."default",
    CONSTRAINT bikes_pkey PRIMARY KEY (id)
)

but creating a row in ForestAdmin fails with "Something creation failed: null value in column "id" violates not-null constraint". I can fix it with adding the default value (defaultValue: sequelize.literal('uuid_generate_v4()'),), but I think this should not be necessary, right?

p0wl avatar Mar 10 '20 10:03 p0wl