Duane Morin
2009-Oct-13 20:32 UTC
ActiveRecord failing with a default field value of blank
I have a bug in my code that''s caught me completely off guard, and I''m hoping that maybe my IT folks updated a gem somewhere that changed something I didn''t know about. I''ve got a field, mq_unsubscribe, in my mail_queue table. It has a non-null constraint on it, and a default value of empty string ''''. (I did not set it up.) I''ve got a simple Model pointed at this table, and have been generating items like this: MailQueueItem.create :template=>3, :subject=>''Foo'', :email=>''duane''.. and so on, which turns nicely into an INSERT into mail_queue (`mq_unsubscribe`, `template`, `subject`, `email`) VALUES (``, 3, `Foo`, `duane`) Note that it recognizes the empty string, and uses that. However, I just discovered I''m now getting this: INSERT into mail_queue (`mq_unsubscribe`, `template`, `subject`, `email`) VALUES (NULL, 3, `Foo`, `duane`) where it''s generating a NULL for my non-specified field, and that''s breaking the constraint. To the best of my ability to figure it out, the code that does the MailQueueItem.create has not in any way changed. I''m hoping that somebody can say "Yes, version X of ActiveRecord now behaves differently in that circumstance..." Fingers crossed! Duane -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Oct-13 21:32 UTC
Re: ActiveRecord failing with a default field value of blank
On Oct 13, 9:32 pm, Duane Morin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > where it''s generating a NULL for my non-specified field, and that''s > breaking the constraint. To the best of my ability to figure it out, > the code that does the MailQueueItem.create has not in any way changed. > > I''m hoping that somebody can say "Yes, version X of ActiveRecord now > behaves differently in that circumstance..." >I do remember some changes on how defaults on text columns on mysql are handled. Does that sounds relevant ? Did your version of activerecord change ? (if so from what to what ?) Fred> Fingers crossed! > > Duane > -- > Posted viahttp://www.ruby-forum.com/.
Greg Donald
2009-Oct-13 23:39 UTC
Re: ActiveRecord failing with a default field value of blank
On Tue, Oct 13, 2009 at 3:32 PM, Duane Morin <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''ve got a field, mq_unsubscribe, in my mail_queue table. It has a > non-null constraint on it, and a default value of empty string ''''. (I > did not set it up.)I''d fix the problem here by making the default null. -- Greg Donald http://destiney.com/
Duane Morin
2009-Oct-14 00:09 UTC
Re: ActiveRecord failing with a default field value of blank
Frederick Cheung wrote:> On Oct 13, 9:32�pm, Duane Morin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> >> where it''s generating a NULL for my non-specified field, and that''s >> breaking the constraint. �To the best of my ability to figure it out, >> the code that does the MailQueueItem.create has not in any way changed. >> >> I''m hoping that somebody can say "Yes, version X of ActiveRecord now >> behaves differently in that circumstance..." >> > > I do remember some changes on how defaults on text columns on mysql > are handled. Does that sounds relevant ? Did your version of > activerecord change ? (if so from what to what ?) > > FredIt appears that there was a mysql upgrade (5.0.45 to 5.0.77) on the day in question, but IT tells me no rails or gem updates. But it doesn''t seem like a mysql thing, as the insert statements would be generated on the Ruby side? It''s a mystery :(. I can fix it easily enough (I''m explicitly setting all my fields now) but still, it''d be nice to know why it suddenly changed. -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Oct-14 20:12 UTC
Re: ActiveRecord failing with a default field value of blank
On Oct 14, 1:09 am, Duane Morin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> It appears that there was a mysql upgrade (5.0.45 to 5.0.77) on the day > in question, but IT tells me no rails or gem updates. But it doesn''t > seem like a mysql thing, as the insert statements would be generated on > the Ruby side? >I think this was a change in how show columns reported defaults - it''s mentionned in the release notes for 5.0.51 (http://dev.mysql.com/doc/ refman/5.0/en/news-5-0-51.html ) Fred> It''s a mystery :(. I can fix it easily enough (I''m explicitly setting > all my fields now) but still, it''d be nice to know why it suddenly > changed. > -- > Posted viahttp://www.ruby-forum.com/.