Forum: Ruby on Rails Postgresql and ActiveRecords problems

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
zven (Guest)
on 2006-04-18 20:37
(Received via mailing list)
Hi all. I have a problem with postgresql PK columns and ActiveRecord.
The error is: PGError: ERROR:  null value in column "item_id" violates
not-null.

Ok, it's wrong to insert NULL into PK columns, but rails doing it. How
to fix? So sad..
Eden B. (Guest)
on 2006-04-18 20:43
(Received via mailing list)
Please post your the model file and the migration or sql file for the
model
you are having problems with.
zven (Guest)
on 2006-04-18 22:40
(Received via mailing list)
On Tue, 2006-04-18 at 09:42 -0700, Eden B. wrote:
>         Ok, it's wrong to insert NULL into PK columns, but rails doing
>         it. How
>         to fix? So sad..
>

I am using Debian with rails-1.1.0 (installed by apt-get), postgresql
8.1

Sql schema:

create table sections
(
  section_id serial,
  name varchar(25) not null,
  title varchar(25),
  primary key(section_id)
);

class SectionController < ApplicationController
  scaffold :section
end

class Section < ActiveRecord::Base
end


class CreateSections < ActiveRecord::Migration
  def self.up
    create_table :sections do |t|
      # t.column :name, :string
    end
  end

  def self.down
    drop_table :sections
  end
end

'NULL' wrong here because it's must be omitted to become a correct
postgres sql query. Correct is: INSERT INTO sections ("name", "title")
VALUES('sdfdsfd', 'sfsdfsd')

T think it's a bug in activerecord ostgresql driver.
Tom M. (Guest)
on 2006-04-18 22:56
(Received via mailing list)
On Apr 18, 2006, at 10:39 PM, zven wrote:

> class SectionController < ApplicationController
>     end
>   end
>
>   def self.down
>     drop_table :sections
>   end
> end
>
> 'NULL' wrong here because it's must be omitted to become a correct
> postgres sql query. Correct is: INSERT INTO sections ("name", "title")
> VALUES('sdfdsfd', 'sfsdfsd')

Primary keys in Rails are assumed to be named 'id'

It can be overridden for legacy schema, but if you do override the
column
name you still access the value as an attribute named 'id'

--
-- Tom M.
zven (Guest)
on 2006-04-18 23:05
(Received via mailing list)
On Tue, 2006-04-18 at 11:53 -0700, Tom M. wrote:
> > );
> >     create_table :sections do |t|
> > postgres sql query. Correct is: INSERT INTO sections ("name", "title")
> > VALUES('sdfdsfd', 'sfsdfsd')
>
> Primary keys in Rails are assumed to be named 'id'
>
> It can be overridden for legacy schema, but if you do override the
> column
> name you still access the value as an attribute named 'id'
>

I know it already ). Problem solved! Thanks to all.
Peter G. (Guest)
on 2006-04-19 01:49
zven wrote:
> On Tue, 2006-04-18 at 11:53 -0700, Tom M. wrote:
>> > );
>> >     create_table :sections do |t|
>> > postgres sql query. Correct is: INSERT INTO sections ("name", "title")
>> > VALUES('sdfdsfd', 'sfsdfsd')
>>
>> Primary keys in Rails are assumed to be named 'id'
>>
>> It can be overridden for legacy schema, but if you do override the
>> column
>> name you still access the value as an attribute named 'id'
>>
>
> I know it already ). Problem solved! Thanks to all.

You should still consider upgrading your rails 1.1.0 to rails 1.1.2.
You'll benefit from numerous bugfixes without introducing unstable new
features.
This topic is locked and can not be replied to.