Hi,
I put the following in my environment.rb file:
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update
(:database_manager => CGI::Session::ActiveRecordStore)
Runnning WEBrick via "script/server" and trying to load any page
served by a controller results in an error like the following:
#<ActiveRecord::StatementInvalid: ERROR: null value in column "id"
violates not-null constraint
: INSERT INTO session ("id", "data") VALUES(NULL,
''BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7AA='')>
I create the session table using the
CGI::Session::ActiveRecordStore::Store.create_table! method, and it
looks like this:
Table "public.session"
Column | Type | Modifiers
------------+---------+-----------
id | integer | not null
session_id | text |
data | text |
Indexes:
"session_pkey" PRIMARY KEY, btree (id)
"session_session_id_key" UNIQUE, btree (session_id)
Does anyone have insight into what''s going on here? I was getting
this problem in a app I was migrating from 0.12, but I created a new
0.13 app from scratch and created some very simple controllers that
work fine when the database is not being used for session storage.
Regards,
Ed
--
Transmogrify, LLC * <http://xmog.com/>
Your "id" column in the table needs to be type "serial" instead of "integer". Kevin On 8/5/05, Ed Watkeys <edw-tIV1OJqwIcc@public.gmane.org> wrote:> Runnning WEBrick via "script/server" and trying to load any page > served by a controller results in an error like the following: > > #<ActiveRecord::StatementInvalid: ERROR: null value in column "id" > violates not-null constraint > : INSERT INTO session ("id", "data") VALUES(NULL, > ''BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo > SGFzaHsABjoKQHVzZWR7AA=> '')> > > I create the session table using the > CGI::Session::ActiveRecordStore::Store.create_table! method, and it > looks like this: > > Table "public.session" > Column | Type | Modifiers > ------------+---------+----------- > id | integer | not null > session_id | text | > data | text |
On Aug 5, 2005, at 11:58 PM, K C wrote:> Your "id" column in the table needs to be type "serial" instead of > "integer".PostgreSQL does not allow inserting nulls into serial columns. I created a new Rails app and did the following: 1) Added the following lines to environment.rb: ActiveRecord::Base.pluralize_table_names = false ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore CGI::Session::ActiveRecordStore::Session.table_name = ''ror_session'' ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update (:database_manager => CGI::Session::ActiveRecordStore) 2) Executed the following statement in my PostgreSQL 8.0.3 database: create table ror_session ( ror_session_id serial, session_id text unique, data text); Why "ror_session"? Because when configured as in 1) to follow well- accepted table naming conventions[IDEF1X], ActiveRecord gets confused: It wants there to be two session_id columns: the primary key and the browser session ID. I recommend changing the name of the session_id attribute to something like "browser_key". 3) Create a dummy model and controller for testing purposes. a) Create the table: create table post (id serial, title character varying, body text); b) Create the model and controller: script/generate scaffold post blog 4) Run the application: script/server 5) Load http://localhost:3000/blog and observe as the following error is generated: #<ActiveRecord::StatementInvalid: ERROR: null value in column "ror_session_id" violates not-null constraint : INSERT INTO ror_session ("ror_session_id", "data") VALUES(NULL, ''BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo SGFzaHsABjoKQHVzZWR7AA='')> If I don''t de-pluralize table names and prefix primary keys with table names, I no longer need to rename the session table, and everything works fine. What I don''t know is what exactly is causing the failure. For reference, the 0.12 database session stuff worked fine with "pluralize_table_names = false" and "primary_key_prefix_type = :table_name_with_underscore". Regards, Ed -- Transmogrify, LLC * <http://xmog.com/>