Hi all, Here''s a funny situation: MySQL 5 does not support default values for columns of type text (and binary). MySQL 5 will throw an error if you try to insert a null value into a column that is NOT NULL. Rails knows that MySQL wrongly reports defaults as '''' for NOT NULL columns with no default specified. Rails also knows which column types don''t allow default values (text, binary). So when rails is dealing with a TEXT NOT NULL column, it''ll know it doesn''t support a default value, and it''ll understand the reported default value of '''' is fake. It''ll assume no default. So here''s the issue: when initializing a new record, rails will set the attribute to nil. Then, when saving it, MySQL will throw because you tried inserting NULL into a NOT NULL column. My suggestion is simple: In the specific case that a column disallows default and is NOT NULL, report the default as MySQL''s implicit default, ''''. The attribute should be initialized to it, and schema dumper should dump the column with said default value. The reasoning is that effectively, '''' IS the default value for a TEXT NOT NULL column. Makes sense? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Calo, I think this is the perfect solution for the problem. -- Ferdinand On Aug 15, 8:38 pm, Caio Chassot <li...@v2studio.com> wrote:> Hi all, > > Here''s a funny situation: > > MySQL 5 does not support default values for columns of type text (and > binary). > > MySQL 5 will throw an error if you try to insert a null value into a > column that is NOT NULL. > > Rails knows that MySQL wrongly reports defaults as '''' for NOT NULL > columns with no default specified. Rails also knows which column > types don''t allow default values (text, binary). > > So when rails is dealing with a TEXT NOT NULL column, it''ll know it > doesn''t support a default value, and it''ll understand the reported > default value of '''' is fake. It''ll assume no default. > > So here''s the issue: when initializing a new record, rails will set > the attribute to nil. Then, when saving it, MySQL will throw because > you tried inserting NULL into a NOT NULL column. > > My suggestion is simple: > > In the specific case that a column disallows default and is NOT NULL, > report the default as MySQL''s implicit default, ''''. The attribute > should be initialized to it, and schema dumper should dump the column > with said default value. > > The reasoning is that effectively, '''' IS the default value for a TEXT > NOT NULL column. > > Makes sense?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Koziarski
2007-Aug-20 05:03 UTC
Re: mysql5 defaults, rails and not null text columns
> Makes sense?This makes sense to me, if you can whip up a patch and have it reviewed we should figure out if it breaks anything else. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On 2007-08-20, at 02:03 , Michael Koziarski wrote:> >> Makes sense? > > This makes sense to me, if you can whip up a patch and have it > reviewed we should figure out if it breaks anything else.http://dev.rubyonrails.org/ticket/9324 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---