ActiveRecord::StatementInvalid: PG::Error: ERROR: null value in column "id" violates not-null constraint

2,123 views
Skip to first unread message

Selva Chezhian

unread,
May 3, 2013, 9:07:02 AM5/3/13
to bangal...@googlegroups.com
Hi All,

I am getting the following error frequently in my application only in production mode. If I restart my rails application this error will not appear for some time.


(0.3ms)  BEGIN
  SQL (0.8ms)  INSERT INTO "databases" ("alias_name", "created_at", "created_by", "id", "name", "site_id", "type", "updated_at", "updated_by") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)  [["alias_name", "name"], ["created_at", Wed, 17 Apr 2013 16:46:25 IST +05:30], ["created_by", nil], ["id", nil], ["name", "name"], ["site_id", 2], ["type", "Directory"], ["updated_at", Wed, 17 Apr 2013 16:46:25 IST +05:30], ["updated_by", nil]]
PG::Error: ERROR:  null value in column "id" violates not-null constraint
: INSERT INTO "databases" ("alias_name", "created_at", "created_by", "id", "name", "site_id", "type", "updated_at", "updated_by") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
   (0.2ms)  ROLLBACK
ActiveRecord::StatementInvalid: PG::Error: ERROR:  null value in column "id" violates not-null constraint

At the time of getting the error in the SQL the id is passing as nil. otherwise the id itself not passing.

In DB the id column is like not null default nextval('directories_id_seq'::regclass)

Rails - 3.1.3

Thanks,
Selva Chezhian

¤=๋●๋•என்றும் அன்புடன்●๋•=¤
Ƹ̵̡Ӝ̵̨̄Ʒ ●๋• செழியன் 007 ●๋• ♥ ツƸ̵̡Ӝ̵̨̄Ʒ
  
【✖ςサ∑zサⅰ∆и 007✖】
セルバシェこんにちは
塞爾瓦桑切斯繼顯

Prakash Murthy

unread,
May 3, 2013, 9:57:26 AM5/3/13
to bangal...@googlegroups.com
My understanding is that 'id' is part of rails magic, and it shouldn't appear in the insert statements shown in the log; wonder what's making it show in the logs....

You might be better off rebuilding the app like this guy did: http://stackoverflow.com/a/7579993/429758 ;-)

~Prakash

--
You received this message because you are subscribed to the Google Groups "BANGALORE RUG-Ruby Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bangalorerug...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Hemant Kumar

unread,
May 4, 2013, 10:44:12 AM5/4/13
to bangal...@googlegroups.com
Hello,

I do not think it is a good idea to have a table named "databases". Also, can you guys post the code which is trying to do this insert?




On Sat, May 4, 2013 at 7:01 PM, kingston.s <jenori...@gmail.com> wrote:
 Hi Prakash,

  I am also facing same issue,i am using rails engine concept so, i have created new application and engine.
 could you please tell me any other way to solve this issue.

 Thanks,
 kingston.s

Krishnaprasad Varma

unread,
May 6, 2013, 1:13:49 AM5/6/13
to bangal...@googlegroups.com
INSERT INTO "databases" ("alias_name", "created_at", "created_by", "name", "site_id", "type", "updated_at", "updated_by") VALUES ($1, $2, $3, $4, $5, $6, $7, $8)

Try skipping the id, and see weather this runs in postgres console.
postgres should increment the id itself. 
Also I second Hemant, I suggest to change the table name.

Krishnaprasad Varma

unread,
May 7, 2013, 2:51:56 AM5/7/13
to bangal...@googlegroups.com
Can you share your schema ?


On Mon, May 6, 2013 at 11:50 AM, kingston.s <jenori...@gmail.com> wrote:
Hi Krishnan,
 
     My table name is tags in that also the same error is coming.

kingston.s  

Kanna Vrk

unread,
Apr 19, 2014, 2:07:05 PM4/19/14
to bangal...@googlegroups.com
for me also same pblm.

Thanks & Regards,
kanna(9742665400)...........

arun vydianathan

unread,
Apr 19, 2014, 7:08:10 PM4/19/14
to bangal...@googlegroups.com
I can see a column named type in the schema?
Are you using it? Rails does some magic with columns named type for polymorphic relations. Is it some clash around that?


For more options, visit https://groups.google.com/d/optout.



--
Thanks,
--
Arun
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you're not on the edge, you're taking up too much room.
Reply all
Reply to author
Forward
0 new messages