I just switched from using a column type of SERIAL to trying to use a
Postgres Sequence defined as:
CREATE SEQUENCE unique_sequence START 101;
The column definition went from “id SERIAL NOT NULL” to
"id INTEGER NOT NULL DEFAULT nextval(‘unique_sequence’), "
When i insert outside of rails, everything works fine. Inside rails,
however, I get this error message:
ERROR C42P01 Mrelation “project_id_seq” does not
exist Fnamespace.c L201 RRangeVarGetRelid
My question is: Do you have to use Serial types on id columns? I would
prefer to use a sequence so i can ensure that the ids of rows in
several tables are entirely unique.
SERIAL is just an alias for ‘integer no null default
nextval(‘sequence’)…’ Looks like Rails is looking
for a sequence named project_id_seq yet you created
one named unique_sequence.
Right, you need the standard sequence name of
“#{table_name}_#{primary_key_column_name}_seq”, unless you use AR’s
set_sequence_name method to name the sequence.
But you will still run into a problem with these explicitly named
sequences in Postgresql that RoR 0.14.2 doesn’t handle:
Modifiers
------------------±-----------------------±---------------------------------------------------
id | integer | not null default
nextval(‘“players_id_seq”’::text)
positie | integer |
active | boolean | not null default false
perm_level | smallint | not null default 1
email | character varying(150) | not null
fname | character varying(60) | not null
lname | character varying(80) | not null
Right, you need the standard sequence name of
“#{table_name}_#{primary_key_column_name}_seq”, unless you use AR’s
set_sequence_name method to name the sequence.
But you will still run into a problem with these explicitly named
sequences in
Postgresql that RoR 0.14.2 doesn’t handle: