0

我正在尝试更改列类型并出现错误。我的模型是Conf,列名是xml。我想把它从 更改:file:binaryxml最初创建为text,然后我将其更改为file与此非常相似的类似迁移文件。我想再次做同样的事情并将类型更改为binary但出现错误。

有迁移文件:

class ChangeConfXmlColumnToBinary < ActiveRecord::Migration
  def up
    change_column :confs, :xml, :binary
  end

  def down
    change_column :confs, :xml, :file
  end
end

这是错误:

==  ChangeConfXmlColumnToBinary: migrating ====================================
-- change_column(:confs, :xml, :binary)
rake aborted!
An error has occurred, this and all later migrations canceled:

undefined method `to_sym' for nil:NilClass/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_definitions.rb:229:in `column'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:506:in `block (2 levels) in copy_table'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:500:in `each'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:500:in `block in copy_table'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_statements.rb:160:in `create_table'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:498:in `copy_table'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:488:in `move_table'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:481:in `block in alter_table'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:480:in `alter_table'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:441:in `change_column'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:466:in `block in method_missing'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `block in say_with_time'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `say_with_time'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:458:in `method_missing'
/home/staj/rails_projects/sample_app/db/migrate/20130826113731_change_conf_xml_column_to_binary.rb:3:in `up'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `block in migrate'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:389:in `migrate'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:528:in `migrate'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:in `call'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:in `block in ddl_transaction'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in `transaction'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:in `ddl_transaction'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:719:in `block in migrate'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `each'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `migrate'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:570:in `up'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/migration.rb:551:in `migrate'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:193:in `block (2 levels) in <top (required)>'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/bin/ruby_noexec_wrapper:14:in `eval'
/home/staj/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

rake db:rollback-- change_column(:confs, :xml, :text)以“ ”开头给出相同的错误

4

1 回答 1

2

看起来“二进制”是一个保留字。看看这个保留词列表

“二进制”一词在MySQLPostgreSQL中都是保留字,因此如果您计划在生产中使用其中任何一个,您可能会遇到问题。

于 2013-08-26T13:09:00.227 回答