Postgresql and ActiveRecords problems

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…

Please post your the model file and the migration or sql file for the
model
you are having problems with.

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.

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.

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