SOLVED: Re: PostgreSQL primary (sequence) key issue (Ruby/Rails)

From: "Andrew Madu" <andrewmadu(at)gmail(dot)com>
To: rubyonrails-talk(at)googlegroups(dot)com, pgsql-general(at)postgresql(dot)org
Subject: SOLVED: Re: PostgreSQL primary (sequence) key issue (Ruby/Rails)
Date: 2007-03-02 03:22:03
Message-ID: ede9a1830703011922w111d16vdf9cd62e33394dd7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
this one has been finally put to bed!!

--
Regards

Andrew

On 01/03/07, Andrew Madu <andrewmadu(at)gmail(dot)com> wrote:
>
> Hi Guys,
> I'm completely stumped with this one!
>
> I've included ActiveRecord::Base.set_sequence_name in my environment.rb,
> and in my user.rb I've placed the following code:
>
> class Usertbl < ActiveRecord::Base
> set_primary_key "user_id"
> set_sequence_name "seq_user_mytable"
> validates_uniqueness_of :userpassword, :username, :scope => :user_id
> end
>
> From http://localhost:3000/usertbl/new I then attempt to enter a new a
> record and receive the following error message:
>
>
> RuntimeError: ERROR C23502 Mnull value in column "user_id" violates not-null constraint
>
>
> FexecMain.c L1795 RExecConstraints: INSERT INTO usertbl
>
>
>
> Oh my head hurts!!
>
> --
> Regards
>
> Andrew
>
>
> On 01/03/07, Andrew Madu < andrewmadu(at)gmail(dot)com> wrote:
> >
> > Hi Dave,
> > my apologies for contacting you off list but i'm having a spot of bother
> > with postgreSQL sequence setup in rails. In addition to what is mentioned
> > below, I have place the following line of code in my environment.rbdocument:
> >
> > # Include your application configuration below
> > ActiveRecord::Base.pluralize_table_names = false
> > ActiveRecord::Base.set_sequence_name
> >
> > What I am overlooking here?
> >
> > --
> > Regards
> >
> > Andrew
> >
> > ---------- Forwarded message ----------
> > From: Andrew Madu < andrewmadu(at)gmail(dot)com>
> > Date: 01-Mar-2007 15:28
> > Subject: Re: PostgreSQL primary (sequence) key issue
> > To: rubyonrails-talk(at)googlegroups(dot)com
> >
> > Hi,
> > I've followed the example given here:
> >
> > http://ar.rubyonrails.com/classes/ActiveRecord/Base.html#M000367
> >
> > and implemented set_sequence_name "seq_name" in my class. When I try to
> > update the user table with a new row from:
> >
> > http://localhost:3000/usertbl/new
> >
> > I get the following error message:
> >
> > RuntimeError: ERROR C23502 Mnull value in column "user_id" violates not-null constraint
> >
> >
> >
> > FexecMain.c L1795 RExecConstraints: INSERT INTO usertbl
> >
> >
> > What am I overlooking here?
> >
> > Also coud possibly give me any clues on how to setup an 'assigned'
> > primary key in an ActiveRecord class?
> >
> > --
> > Regards
> >
> > Andrew
> >
> > On 01/03/07, Andrew Madu <andrewmadu(at)gmail(dot)com> wrote:
> > >
> > > Hi,
> > > I have a sequence set up on one of my tables called seq_user_mytable.
> > > I tried the following with no joy:
> > >
> > > set_primary_key "user_id", :sequence => "seq_user_mytable" and:
> > >
> > > ActiveRecord:: Base.seq_user_mytable
> > >
> > > again with no joy. How do I implement a sequence in
> > > Rails/ActiveRecord?
> > >
> > > --
> > > Regards
> > >
> > > Andrew
> > >
> >
> >
>

Browse pgsql-general by date

  From Date Subject
Next Message Postgres User 2007-03-02 03:39:01 Re: Fun with Cursors- how to rewind a cursor
Previous Message Terry Fielder 2007-03-02 01:42:48 Re: Thanks to all