In my Postgresql tables, I explicitly create a sequence and use it in
the column definition as the default value for the primary key. I do
this in the same manner that the companies table defined in
test/fixtures/db_definitions/postgresql.sql.
CREATE SEQUENCE companies_nonstd_seq START 101;
CREATE TABLE companies (
id integer DEFAULT nextval('companies_nonstd_seq'),
"type" character varying(50),
"ruby_type" character varying(50),
firm_id integer,
name character varying(50),
client_of integer,
rating integer default 1,
PRIMARY KEY (id)
);
The current pk_and_sequence_for in 0.14.1 does not work in this case.
I don't know how to fix it, but I have a patch that adds a test to the
fixture test case that shows the failure, so that should help a bit.
Having this code not work is currently causing my application test
suite to fail, since the fixture is loading data into the table, but
the sequence is still at 1 when I try to save a brand new row into the
table, so I get this error:
ActiveRecord::StatementInvalid: ERROR: duplicate key violates unique
constraint "post_pkey"
Regards,
Blair