Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

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

Open
prevostc opened this issue Aug 6, 2018 · 4 comments

Comments

@prevostc
Copy link

prevostc commented Aug 6, 2018

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 prevostc changed the title Can't create a new entity, default value ignored Default value ignored Aug 6, 2018
@arnaudbesnier arnaudbesnier changed the title Default value ignored [+] Default Values - Lumber should generate the models based on the columns default values Aug 23, 2018
@arnaudbesnier
Copy link
Member

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.

@p0wl
Copy link

p0wl commented Mar 9, 2020

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

@arnaudbesnier
Copy link
Member

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.

@p0wl
Copy link

p0wl commented Mar 10, 2020

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants