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/>