Forum: Ruby on Rails active migration gives undefined_method 'string_to_binary'

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
36958dd94ca666a38483df282a5214d5?d=identicon&s=25 Peter Ertl (Guest)
on 2006-03-04 09:10
(Received via mailing list)
has anyone ever seen that:

c:\rails\test>rake migrate --trace
(in c:/rails/test)
** Invoke migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute migrate
rake aborted!
undefined method `string_to_binary' for
ActiveRecord::ConnectionAdapters::ColumnDefinition:Class
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapt
er.rb:119:in
`quote'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/sc
hema_statements.rb:245:in
`add_column_options!'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/sc
hema_definitions.rb:180:in
`add_column_options!'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/sc
hema_definitions.rb:169:in
`to_s'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/sc
hema_definitions.rb:249:in
`*'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/sc
hema_definitions.rb:249:in
`to_sql'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/sc
hema_statements.rb:92:in
`create_table'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapt
er.rb:283:in
`create_table'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/migration.rb:170:in
`send'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/migration.rb:170:in
`method_mis
sing'
./db/migrate//001_init.rb:4:in
`up'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/migration.rb:228:in
`send'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/migration.rb:228:in
`migrate'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/migration.rb:223:in
`each'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/migration.rb:223:in
`migrate'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/migration.rb:190:in
`up'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/migration.rb:181:in
`migrate'
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/tasks/databases.rake:3
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/tasks/databases.rake:2:in
`call'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:232:in `execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:232:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:232:in `execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:202:in `invoke'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:195:in
`synchronize'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:195:in `invoke'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:1719:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:1719:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:1719:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.0/bin/rake:7
c:/ruby/bin/rake:18:in `load'
c:/ruby/bin/rake:18

this line "data" causes the error:

    create_table "article_images", :force => true do |t|
      t.column "article_id", :integer, :limit => 10, :default => 0
      t.column "data", :binary, :default => "", :null => false
      t.column "content_type", :string, :limit => 45, :default => "",
:null
=> false
      t.column "position", :integer, :limit => 10, :default => 0
      t.column "updated_at", :timestamp
      t.column "shop_id", :integer, :limit => 10, :default => 0, :null
=>
false
    end

i am migrating towards mysql 5.0.18.

is it a known bug of rails?

Regards
Peter
97a7959f0d9e6c90ddae200520e93067?d=identicon&s=25 Damon Clinkscales (Guest)
on 2006-03-05 20:31
Peter Ertl wrote:
[snip]
> rake aborted!
> undefined method `string_to_binary' for
> ActiveRecord::ConnectionAdapters::ColumnDefinition:Class
[snip]
> this line "data" causes the error:
>
>     create_table "article_images", :force => true do |t|
>       t.column "article_id", :integer, :limit => 10, :default => 0
>       t.column "data", :binary, :default => "", :null => false
>       t.column "content_type", :string, :limit => 45, :default => "",
> :null
> => false
>       t.column "position", :integer, :limit => 10, :default => 0
>       t.column "updated_at", :timestamp
>       t.column "shop_id", :integer, :limit => 10, :default => 0, :null
> =>
> false
>     end
>
> i am migrating towards mysql 5.0.18.
>
> is it a known bug of rails?
I don't know if there is a bug filed on it or not.  It has certainly
been mentioned on the list before.  There are two things to note:

1.  The data column has been output (most likely by the schema dumper)
as a binary column with a :default => "".  This of course makes no
sense.  Remove the default clause and the error will probably go away.
Of course, the unfortunate thing about this is that you can't rely on
schema.rb (re-generated on every migration step) as a reliable
representation of your schema.

2.  The string_to_binary method is present on the Column class, but not
the ColumnDefinition class in Rails 1.0.  Based on a reading of the code
it looks like the correct place is in the Column class, however in
schema_statements.rb a ColumnDefinition object may be returned from the
column() method.  That object does not have a string_to_binary method.
Some folks on the list have solved this problem by adding this to the
ColumnDefinition class (although this is just a hack).

      # Used to convert from Strings to BLOBs
      def self.string_to_binary(value)
        value
      end

-damon
http://damonclinkscales.com/
This topic is locked and can not be replied to.