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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to