# Postgres sequencer and rails

**URL:** <https://www.ruby-forum.com/t/postgres-sequencer-and-rails/120528>\
**Category:** Rails\
**Created:** [November 18, 2007, 12:18am UTC](https://www.ruby-forum.com/t/postgres-sequencer-and-rails/120528 "2007-11-18T00:18:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![blindmen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/50afbb/32.png) [@blindmen](https://www.ruby-forum.com/u/blindmen)\
**Post date:** [November 18, 2007, 12:18am UTC](https://www.ruby-forum.com/t/postgres-sequencer-and-rails/120528/1 "2007-11-18T00:18:04Z")

</div>

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.
