You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When upserting a record in a database column is not nullable and has a default value, ActiveRecord::Upsert attemps to insert a nil value. This raises an exception:
PG::NotNullViolation: ERROR: null value in column "uuid" violates not-null constraint
The table looks like this:
CREATETABLEpublic.defaulting_records (
id bigintNOT NULL,
uuid uuid DEFAULT public.gen_random_uuid() NOT NULL,
name character varying,
created_at timestamp without time zoneNOT NULL,
updated_at timestamp without time zoneNOT NULL
);
And the SQL generated for the upsert is as follows:
INSERT INTO"defaulting_records" ("uuid", "name", "created_at", "updated_at") VALUES ($1, $2, $3, $4) ON CONFLICT ("id") DO UPDATESET"name"= $5, "updated_at"= $6 RETURNING *, (xmax =0) AS _upsert_created_record
One way to solve this is to continue the class-level and opts: API to allow passing an excluded_keys array. This would be easy to implement in e.g. rails51.rb by removing the excluded keys from upsert_keys
When upserting a record in a database column is not nullable and has a default value, ActiveRecord::Upsert attemps to insert a nil value. This raises an exception:
The table looks like this:
And the SQL generated for the upsert is as follows:
Failing test available in this branch: https://github.com/andrewclink/active_record_upsert/tree/upsert_null
The text was updated successfully, but these errors were encountered: