Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I interpret this Rails/PostgreSQL error?

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.)

like image 714
steven_noble Avatar asked Nov 22 '25 08:11

steven_noble


1 Answers

i also got same problem when i check it seems i have nested transaction

if You got same problem try to find

ActiveRecord::Base.transaction

and remove it

because seems created_at doesn't assigned when You use transaction (maybe bug)

hope it helps

like image 109
qoyyim Avatar answered Nov 24 '25 21:11

qoyyim