简体   繁体   中英

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

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

It says: "null value in column "created_at" violates not-null constraint" when you run:

INSERT INTO "elements" ("updated_at") VALUES ('2014-05-08 13:27:56.002747')

Meaning that:

  • You're missing some kind of default value for the created_at field; or
  • You should set a created_at manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM