当我运行rake db:migrate
时,我有一个简单的Rails迁移失败。这是在使用SQLite3的开发环境中。这是迁移:
class RemoveMobileUserIdFromDevices < ActiveRecord::Migration
def up
remove_column :devices, :mobile_user_id
end
def down
add_column :devices, :mobile_user_id, :integer
end
end
运行rake db:migrate
时出现以下错误:
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
== RemoveMobileUserIdFromDevices: migrating ==================================
-- remove_column(:devices, :mobile_user_id)
rake aborted!
An error has occurred, this and all later migrations canceled:
incompatible character encodings: ASCII-8BIT and UTF-8
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:516:in `*'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:516:in `block in copy_table_contents'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/result.rb:20:in `block in each'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/result.rb:20:in `each'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/result.rb:20:in `each'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:514:in `copy_table_contents'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:478:in `copy_table'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:455:in `move_table'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:448:in `block in alter_table'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:447:in `alter_table'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:387:in `block in remove_column'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:386:in `each'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:386:in `remove_column'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:447:in `block in method_missing'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:422:in `block in say_with_time'
/Users/username/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/benchmark.rb:280:in `measure'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:422:in `say_with_time'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:442:in `method_missing'
/Users/username/[removed]/[removed]/db/migrate/20120127204256_remove_mobile_user_id_from_devices.rb:3:in `up'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:394:in `block (2 levels) in migrate'
/Users/username/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/benchmark.rb:280:in `measure'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:394:in `block in migrate'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:185:in `with_connection'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:375:in `migrate'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:507:in `migrate'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:687:in `block (2 levels) in migrate'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:742:in `call'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:742:in `block in ddl_transaction'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/transactions.rb:208:in `transaction'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:742:in `ddl_transaction'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:686:in `block in migrate'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:671:in `each'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:671:in `migrate'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:549:in `up'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/migration.rb:530:in `migrate'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/railties/databases.rake:161:in `block (2 levels) in <top (required)>'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/username/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/username/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/username/.rvm/gems/ruby-1.9.3-p0/bin/rake:19:in `load'
/Users/username/.rvm/gems/ruby-1.9.3-p0/bin/rake:19:in `<main>'
Tasks: TOP => db:migrate
我不确定问题是什么,因为我之前已经使用类似的命令进行了迁移,这些命令没有问题。到目前为止,我已尝试在TextMate中手动键入迁移文件(假设实际文件可能具有错误的字符编码)。我还删除了迁移并通过rails g migration RemoveMobileUserIdFromDevices mobile_user_id:integer
重新创建了它,但没有看到任何变化。