0

After upgrading my Rails application from 3.2.13 to 4.0.0, migration command fails saying "version is defined by Active Record".

When I looked in MySQL database, there is schema_migrations table and a column named "version", and this seems conflicting with ActiveRecord method.

Would someone have any idea to fix this problem?

Part of my Gemfile

  • actionmailer (4.0.0)
  • actionpack (4.0.0)
  • actionpack-action_caching (1.0.0)
  • actionpack-page_caching (1.0.0)
  • activemodel (4.0.0)
  • activerecord (4.0.0)
  • activerecord-deprecated_finders (1.0.3)
  • activesupport (4.0.0)
  • mysql2 (0.3.13)

Errors

Tested in clean database which doesn't have any tables, but incremental migration also fails.

After hitting the command, I see the table schema_migrations generated with a column "version" with no record, but :users table is created. So schema_migrations.version is properly setting a migration version of :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)>'

Also tried rake db:setup

$ 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)
4

1 回答 1

2

问题出在 paper_trail 上,它有一个名为 Version 的类并与 rails 4 中断。确保您的 paper_trail gem 已更新为支持版本

 gem 'paper_trail', '>= 3.0.0.beta1'
于 2013-10-14T16:59:44.033 回答