Activerecord sets the columns that are not specified to NULL. Postgres
presumes that since your insert statement said to set the column to
null you meant to set it null and ignores the default. Is there a way
to tell activerecord not set missing attributes to null?
Activerecord sets the columns that are not specified to NULL. Postgres
presumes that since your insert statement said to set the column to
null you meant to set it null and ignores the default. Is there a way
to tell activerecord not set missing attributes to null?
I don’t think so - I think activerecord is expecting to be able to
read the default values out of the database schema, although that
assumes that the default is some fixed value.
It should be possible to do something like this though, since updates
only write unchanged columns.
Activerecord sets the columns that are not specified to NULL. Postgres
presumes that since your insert statement said to set the column to
null you meant to set it null and ignores the default. Is there a way
to tell activerecord not set missing attributes to null?
I don’t think so - I think activerecord is expecting to be able to
read the default values out of the database schema, although that
assumes that the default is some fixed value.
It should be possible to do something like this though, since updates
only write unchanged columns.
In postgres sometimes the default values are functions like for
example UUID fields. It would work fine if it sent DEFAULT instead of
NULL for the missing fields and of course it could just not mention
them either.
I was wondering if there is a flag somewhere in AR that says “Don’t
send NULLs for missing attributes” or something.
I don’t think so - I think activerecord is expecting to be able to
read the default values out of the database schema, although that
assumes that the default is some fixed value.
It should be possible to do something like this though, since updates
only write unchanged columns.
In postgres sometimes the default values are functions like for
example UUID fields. It would work fine if it sent DEFAULT instead of
NULL for the missing fields and of course it could just not mention
them either.
I was wondering if there is a flag somewhere in AR that says “Don’t
send NULLs for missing attributes” or something.
Hi,
Were there any updates on this? I’m facing the same problem. Any
solution?
Regards
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.