2013-08-26 38 views
0

我想改變一個列類型並且得到錯誤。我的模特是Conf,專欄名稱是xml。我想將其從:file更改爲:binaryxml最初創建爲text,然後我將它更改爲file,它帶有一個類似於此類似的遷移文件。我想再次做同樣的事情並將其類型更改爲binary但出現錯誤。rails 3在change_column類型中的遷移錯誤

有遷移文件:

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/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_definitions.rb:229:in `column' 
/home/staj/.rvm/gems/[email protected]/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/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:500:in `each' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:500:in `block in copy_table' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_statements.rb:160:in `create_table' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:498:in `copy_table' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:488:in `move_table' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:481:in `block in alter_table' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:480:in `alter_table' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:441:in `change_column' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:466:in `block in method_missing' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `block in say_with_time' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `say_with_time' 
/home/staj/.rvm/gems/[email protected]/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/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `block (2 levels) in migrate' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `block in migrate' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:389:in `migrate' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:528:in `migrate' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:720:in `block (2 levels) in migrate' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:in `call' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:in `block in ddl_transaction' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in `transaction' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:in `ddl_transaction' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:719:in `block in migrate' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `each' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `migrate' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:570:in `up' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/migration.rb:551:in `migrate' 
/home/staj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:193:in `block (2 levels) in <top (required)>' 
/home/staj/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `eval' 
/home/staj/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `<main>' 
Tasks: TOP => db:migrate 
(See full trace by running task with --trace) 

rake db:rollback給出了同樣的錯誤與年初

+0

你正在使用'mysql'或'postgresql'? – Salil

+0

確保您使用的數據庫支持二進制數據類型 – techvineet

+0

@Salil是sqllite – overflow

回答

2

它看起來像 「-- change_column(:confs, :xml, :text)」, 「二進制」是一個保留字。看看這個list of reserve words

單詞「二進制」是在這兩個MySQL & PostgreSQL保留字,所以如果你打算使用任何這些在生產中你可能會遇到問題。

+0

@ 8bithero,我正在使用sqllite – kalahari