I’m wrestle with postgres database and rails.
Finally it’s working but i need some explanation :
I have a sequencer :
CREATE SEQUENCE players_id_seq
ALTER TABLE players_id_seq OWNER TO squash;
CREATE TABLE players
id bigserial NOT NULL,
firstname character varying,
lastname character varying,
CONSTRAINT primaery_key_players PRIMARY KEY (id)
ALTER TABLE players OWNER TO squash;
First Error was that sequencer was not initialized on the beginning of
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
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
class PlayersController < ApplicationController