将我的Rails应用程序从3.2.13升级到4.0.0后,迁移命令失败,说“版本由Active Record定义”。
当我查看MySQL数据库时,有schema_migrations表和一个名为“version”的列,这似乎与ActiveRecord方法冲突。
有人有任何想法解决这个问题吗?
在没有任何表的干净数据库中测试过,但增量迁移也失败了。
点击命令后,我看到使用没有记录的列“version”生成的表schema_migrations,但是:创建了users表。因此,schema_migrations.version正在正确设置迁移版本:users。
$ RAILS_ENV=test rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
== DeviseCreateUsers: migrating ==============================================
-- create_table(:users)
-> 0.0289s
== DeviseCreateUsers: migrated (0.0290s) =====================================
rake aborted!
An error has occurred, all later migrations canceled:
version is defined by Active Record/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:59:in `instance_method_already_implemented?'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:282:in `block in define_attribute_method'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `each'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `define_attribute_method'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `block in define_attribute_methods'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `each'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `define_attribute_methods'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:29:in `block in define_attribute_methods'
<internal:prelude>:10:in `synchronize'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `define_attribute_methods'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:167:in `respond_to?'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:368:in `__define_callbacks'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:79:in `run_callbacks'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/validations/callbacks.rb:106:in `run_validations!'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/validations.rb:314:in `valid?'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/validations.rb:70:in `valid?'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/validations.rb:77:in `perform_validations'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/validations.rb:57:in `save!'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/attribute_methods/dirty.rb:41:in `save!'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/transactions.rb:275:in `block in save!'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/transactions.rb:209:in `transaction'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/transactions.rb:275:in `save!'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/protected_attributes-1.0.3/lib/active_record/mass_assignment_security/validations.rb:17:in `create!'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:990:in `record_version_state_after_migrating'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:960:in `block in execute_migration_in_transaction'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:1007:in `ddl_transaction'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:958:in `execute_migration_in_transaction'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:920:in `block in migrate'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:916:in `each'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:916:in `migrate'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `up'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:742:in `migrate'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/Users/devuser/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
$ RAILS_ENV=test rake db:setup
my_table already exists
-- create_table("users", {:force=>true})
-> 0.0203s
-- initialize_schema_migrations_table()
-> 0.0007s
rake aborted!
version is defined by Active Record
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:59:in `instance_method_already_implemented?'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:282:in `block in define_attribute_method'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `each'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `define_attribute_method'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `block in define_attribute_methods'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `each'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `define_attribute_methods'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:29:in `block in define_attribute_methods'
<internal:prelude>:10:in `synchronize'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `define_attribute_methods'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:167:in `respond_to?'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:368:in `__define_callbacks'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:79:in `run_callbacks'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/core.rb:216:in `init_with'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/persistence.rb:55:in `instantiate'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `block in find_by_sql'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `block in each'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `map'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `find_by_sql'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/relation.rb:585:in `exec_queries'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/relation.rb:471:in `load'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/relation.rb:220:in `to_a'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:12:in `map'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:787:in `get_all_versions'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:949:in `migrated'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/migration.rb:944:in `pending_migrations'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:164:in `block (2 levels) in <top (required)>'
/Users/devuser/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:abort_if_pending_migrations
(See full trace by running task with --trace)
答案 0 :(得分:2)
问题在于paper_trail,它有一个名为Version的类并且使用rails 4断开。确保你的paper_trail gem更新为支持版本
gem 'paper_trail', '>= 3.0.0.beta1'