Brock Weaver
2005-Sep-12 15:59 UTC
Rails / PostgreSQL / varchar column during insert ignored?
I''m trying to insert a new record into a "users" table in postgresql 8.0.1. This table has the following layout (irrelevent portions removed): id int4 NOT_NULL role_code char(1) NOT_NULL name varchar(30) NOT_NULL ... id is primary key. When I go to save, here''s the parameters passed to the controller: Processing AdminController#add_user (for 127.0.0.1 <http://127.0.0.1> at Mon Sep 12 10:48:46 Central Daylight Time 2005) Parameters: {"user"=>{"role_code"=>"G", "name"=>"joe", "first_name"=>"Joe", "password"=>"joe", "last_name"=>"Sixpack", "email"=>"js-Gtb4gyMgUa9l57MIdRCFDg@public.gmane.org"}, "action"=>"add_user", "controller"=>"admin"} So you can see, the parameter in question (name) is being passed from the browser to the server and mapped successfully. However, I get the SQL failure: ActiveRecord::StatementInvalid (ERROR C23502 Mnull value in column "first_name" violates not-null constraint FexecMain.c L1732 RExecConstraints: INSERT INTO users ("name", "role_code", "first_name", "last_name", "password", "email") VALUES(''joe'', ''G'', NULL, NULL, NULL, NULL)): So the "name" attribute (among others) is not being mapped from the controller to the ActiveRecord correctly. All NULL parameters are of varchar datatype in postgresql -- so my guess is that varchar columns aren''t working correctly with this table. However, I have another table which has varchars and those work successfully. Ruby version is 1.8.2 on winXP, using WEBrick for the server (yes, I bounced it). Any ideas? -- Brock Weaver brockweaver-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org /* you are not expected to understand this */ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Brock Weaver
2005-Sep-12 16:09 UTC
Re: Rails / PostgreSQL / varchar column during insert ignored?
I apologize, I found the problem. I had specified attr_accessible and attr_accessor macros for the columns that were working correctly, but not the ones that were failing. Sorry for the noise. On 9/12/05, Brock Weaver <brockweaver-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m trying to insert a new record into a "users" table in postgresql 8.0.1. > This table has the following layout (irrelevent portions removed): > > id int4 NOT_NULL > role_code char(1) NOT_NULL > name varchar(30) NOT_NULL > ... > > id is primary key. > > When I go to save, here''s the parameters passed to the controller: > > Processing AdminController#add_user (for 127.0.0.1 <http://127.0.0.1> at > Mon Sep 12 10:48:46 Central Daylight Time 2005) > Parameters: {"user"=>{"role_code"=>"G", "name"=>"joe", > "first_name"=>"Joe", "password"=>"joe", "last_name"=>"Sixpack", "email"=>" > js-Gtb4gyMgUa9l57MIdRCFDg@public.gmane.org"}, "action"=>"add_user", "controller"=>"admin"} > > So you can see, the parameter in question (name) is being passed from the > browser to the server and mapped successfully. However, I get the SQL > failure: > > ActiveRecord::StatementInvalid (ERROR C23502 Mnull value in column > "first_name" violates not-null constraint FexecMain.c L1732 > RExecConstraints: INSERT INTO users ("name", "role_code", "first_name", > "last_name", "password", "email") VALUES(''joe'', ''G'', NULL, NULL, NULL, > NULL)): > > So the "name" attribute (among others) is not being mapped from the > controller to the ActiveRecord correctly. All NULL parameters are of varchar > datatype in postgresql -- so my guess is that varchar columns aren''t working > correctly with this table. However, I have another table which has varchars > and those work successfully. > > Ruby version is 1.8.2 on winXP, using WEBrick for the server (yes, I > bounced it). > > Any ideas? > > > -- > Brock Weaver > brockweaver-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > /* you are not expected to understand this */-- Brock Weaver brockweaver-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org /* you are not expected to understand this */ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails