Hi All,
I’m wrestle with postgres database and rails.
Finally it’s working but i need some explanation :
So :
I have a sequencer :
CREATE SEQUENCE players_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 4
CACHE 1;
ALTER TABLE players_id_seq OWNER TO squash;
Table :
CREATE TABLE players
(
id bigserial NOT NULL,
firstname character varying,
lastname character varying,
CONSTRAINT primaery_key_players PRIMARY KEY (id)
)
WITH (OIDS=FALSE);
ALTER TABLE players OWNER TO squash;
First Error was that sequencer was not initialized on the beginning of
the session.
I’ve solve this : see “Ruby and Postgres” Subject maybe 2 days ago on
the same forum.
Next : When i didn’t have default value set on ID i was experiencing
not-null constraint violation. So i’ve googled something like this :
ALTER TABLE players ALTER COLUMN id SET DEFAULT
nextval(‘players_id_seq’::regclass);
And it is working now.
Question is :
When i didn’t have default value set and not-null attribute set on ID.
Rails was doing inserts only on firstname and lastname values, without
setting the id. But he was complaining about non-initialized sequencer.
So why he was trying to use sequencer when than he didn’t use the value
to fill id field ?
What is the the standard procedure to store new record when only basic
inheritance of model and controller is used ?
class Player < ActiveRecord::Base
end
class PlayersController < ApplicationController
scaffold:player
end
thanks.