I'm getting the following error in Rails with PostgreSQL:
ActiveRecord::StatementInvalid:
PG::NotNullViolation: ERROR: null value in column "created_at" violates not-null constraint
DETAIL: Failing row contains (4, null, null, 2014-05-08 13:27:56.002747, f, null, null, f, f).
: INSERT INTO "elements" ("updated_at") VALUES ('2014-05-08 13:27:56.002747') RETURNING "id"
I gather it's saying I'm attempting to insert the value of 2014-05-08 13:27:56.002747 into the updated_at column of a row representing one instance of Element. Is that correct?
This should be fine, as the value looks like a valid date/time to me — correct?
I also gather it's saying created_at can't be null but that seems crazy because doesn't every instance automatically get a created_at value equal to the date/time at which it was created?
And what does RETURNING "id" mean?
I'm happy to continue debugging my app myself, but if anyone could unpack this error message for me it would be a great headstart. (Especially as the stack trace is not making it clear where the error is being created.)
created_atisNOT NULLandDEFAULT NULL(as you wrote in the comment to @denis), thus theINSERTfails since you are trying to create a row with aNULLvalue for thecreated_atcolumn. Can you write the Ruby code which generates this error?DEFAULT NULL?defaultvalue forcreated_atcolumn, so Rails doesn't set it so the default value is set asNULLin the PostgreSQL column definition. Now that I'm thinking about it, something liket.datetime 'created_at', null: false, default: 'NOW()'could fix the issueRETURNING *is a PG feature which provides the values of the of the values of the created record; it is used by Rails in order to know which is the id of the created record.