This project is archived and is in readonly mode.
Binary table default values
Reported by Oliver Friedrichs | October 26th, 2008 @ 06:12 PM | in 2.3.4
I have an existing database, with a schema that has binary columns, and a default value for those columns (in this case "0000000000000000"). I am trying to extract the schema using "rake --trace db:schema:dump", and am getting the following error: ** Execute db:schema:dump rake aborted! binary columns cannot have a default value: "0000000000000000" Clearly it does not like default binary values.
I was told that this is in fact bug; and not a limitation of ROR. If anyone has any advice on a workaround, I would appreciate it.
Comments and changes to this ticket
-
Pratik March 10th, 2009 @ 12:47 PM
- Assigned user set to Pratik
- State changed from new to incomplete
You should try to submit a failing test case. http://guides.rails.info/contrib... would come handy :)
Thanks.
-
CancelProfileIsBroken August 5th, 2009 @ 03:26 PM
- Tag changed from binary, database, tables to binary, bugmash, database, tables
-
Jeremy Kemper August 10th, 2009 @ 02:57 AM
- State changed from incomplete to invalid
- Tag changed from binary, bugmash, database, tables to binary, database, tables
- Milestone cleared.
Correct: MySQL does not permit default values for BLOB or TEXT columns. You can provide one, but MySQL will silently ignore it.
Workaround: provide your own default when you create new records using a before_create callback.
-
Jatinder Singh August 10th, 2009 @ 03:10 AM
Correct MySQL doesn't permit default values for BLOB or TEXT columns. but MySQL has BINARY and VARBINARY types(which support default values), and AR considers them as as type "binary". here is relevant piece of code from schema_definitions.rb,
def simplified_type(field_type) case field_type when /int/i :integer when /float|double/i :float when /decimal|numeric|number/i extract_scale(field_type) == 0 ? :integer : :decimal when /datetime/i :datetime when /timestamp/i :timestamp when /time/i :time when /date/i :date when /clob/i, /text/i :text when /blob/i, /binary/i :binary when /char/i, /string/i :string when /boolean/i :boolean end end
I think its right for AR to consider BINARY and VARBINARY as BINARY type, and utilize methods like string_to_binary with them. The only difference I see is with default values. here is a potential fix for the problem, http://gist.github.com/164981. let me know how it looks and I can create a patch for it.
-
Jeremy Kemper August 10th, 2009 @ 03:14 AM
- State changed from invalid to open
- Milestone set to 2.3.4
Indeed. The fix looks good!
-
Jatinder Singh August 10th, 2009 @ 03:17 AM
I'll create a patch for this fix and missing tests for MySQLColumn.
-
Jatinder Singh August 10th, 2009 @ 03:22 AM
- Tag changed from binary, database, tables to binary, bugmash, database, tables
-
Jatinder Singh August 10th, 2009 @ 04:51 AM
- Tag changed from binary, bugmash, database, tables to activerecord, binary, bugmash, database, mysql, tables
I've attached a patch with tests for the fix for master. Patch for 2.3-stable coming up next.
-
Jatinder Singh August 10th, 2009 @ 04:53 AM
- Tag changed from activerecord, binary, bugmash, database, mysql, tables to activerecord, binary, bugmash, database, mysql, patch, tables
-
Jatinder Singh August 10th, 2009 @ 05:00 AM
I just realized that the same patch gets applied to 2-3-stable successfully.
-
Repository August 10th, 2009 @ 05:06 AM
- State changed from open to committed
(from [8a49af31581095a35b6dc8b20ed12c2f9fb80855]) AR should respect default values for MySQL BINARY and VARBINARY columns.
[#1273 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/8a49af31581095a35b6dc8b20ed12c... -
Repository August 10th, 2009 @ 05:06 AM
(from [5704ecffadffa04981ec5999c362cb691d4a676e]) AR should respect default values for MySQL BINARY and VARBINARY columns.
[#1273 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/5704ecffadffa04981ec5999c362cb... -
Jeremy Kemper August 10th, 2009 @ 05:06 AM
- Tag changed from activerecord, binary, bugmash, database, mysql, patch, tables to activerecord, binary, database, mysql, patch, tables
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1273 Binary table default values [#1273 state:committed]
- 1273 Binary table default values [#1273 state:committed]