Hey all, I''m new to rails so forgive me if I''m missing something obvious. I''ve got a few tables with a bunch of columns declared like so: NOT NULL DEFAULT "" When I create an instance of one of the models and try to save it ActiveRecord chokes because it tries to insert nulls for any undefined attributes. Is there an easy way to override this behavior? Not so easy way? :-/ Thanks in advance! Tim
NOT NULL DEFAULT "" is bad design. If you want to allow empty strings, then don''t set them to not null. If you want them to be actual values (like current_timestamp, an ID, etc.) then set them to not null. Joe -- Posted via http://www.ruby-forum.com/.
Joe wrote:> If you want to allow empty strings, > then don''t set them to not null.Er, ignore that sentence. What I meant is that it''s better to store null (which means unknown) values rather than just empty strings. Joe -- Posted via http://www.ruby-forum.com/.
Although in MySQL Query Browser in Windows, the program likes to set NOT NULL text columns to have a default value of "". It doesn''t really seem to make sense to make a column NOT NULL and then make the default value NULL. On the other hand, I have never had this particular problem with Rails. In fact, I have trouble with ActiveRecord writing "" for blank form fields, in which case I have to set them to nil manually. -- Posted via http://www.ruby-forum.com/.