26

我正在为基于 Quiz 的小型应用程序使用 Active Admin gem。但是当我执行rake db:migrate时,它​​给了我错误。以下是命令的跟踪:

$ rake db:migrate RAILS_ENV=production --trace
** 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
==  DeviseCreateAdminUsers: migrating =========================================
-- create_table(:admin_users)
rake aborted!
An error has occurred, all later migrations canceled:

undefined method `database_authenticatable' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x9dee690>
/home/users/Documents/Quiz/db/migrate/20120509055635_devise_create_admin_users.rb:4:in `block in change'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:160:in `create_table'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/connection_adapters  /abstract_mysql_adapter.rb:432:in `create_table'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:466:in `block in method_missing'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:438:in `block in say_with_time'
/home/users/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/benchmark.rb:295:in `measure'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:438:in `say_with_time'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:458:in `method_missing'
/home/users/Documents/Quiz/db/migrate/20120509055635_devise_create_admin_users.rb:3:in `change'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:407:in `block (2 levels) in migrate'
/home/users/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/benchmark.rb:295:in `measure'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:407:in `block in migrate'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:119:in `with_connection'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:389:in `migrate'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:528:in `migrate'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:777:in `call'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:777:in `ddl_transaction'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:719:in `block in migrate'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:700:in `each'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:700:in `migrate'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:570:in `up'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/migration.rb:551:in `migrate'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.3/lib/active_record/railties/databases.rake:153:in `block (2 levels) in <top (required)>'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/users/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/users/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/users/.rvm/gems/ruby-1.9.2-p318/bin/rake:19:in `load'
/home/users/.rvm/gems/ruby-1.9.2-p318/bin/rake:19:in `<main>'
Tasks: TOP => db:migrate

以下是我的 GemFile :

source 'https://rubygems.org'

gem 'rails', '3.2.3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2'
gem 'devise'
gem 'activeadmin', :git => 'https://github.com/gregbell/active_admin.git'
gem 'therubyracer'
gem 'formtastic'
gem 'haml'
gem 'paperclip'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platform => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

20120509055635_devise_create_admin_users.rb的内容是

class DeviseCreateAdminUsers < ActiveRecord::Migration
  def change
    create_table(:admin_users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable

      # t.encryptable
      # t.confirmable
      # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
      # t.token_authenticatable


      t.timestamps
    end

    # Create a default user
    AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password')

    add_index :admin_users, :email,                :unique => true
    add_index :admin_users, :reset_password_token, :unique => true
    # add_index :admin_users, :confirmation_token,   :unique => true
    # add_index :admin_users, :unlock_token,         :unique => true
    # add_index :admin_users, :authentication_token, :unique => true
  end

end

我搜索了上述问题并得到了这个,但这并没有帮助我。我到处都找到了这个解决方案。以前有没有人遇到过这个问题,如果有,你做了什么来解决这个问题?对此的任何帮助将不胜感激。谢谢

4

5 回答 5

44

当我尝试部署到新的登台服务器时,我在现有应用程序上也遇到了这个问题。

最后是 Devise gem 已更新到 2.1,我没有修复迁移以在新版本中正常工作。

请务必在他们的 wiki 上通读他们到 2.1 文档的迁移——https: //github.com/plataformatec/devise/wiki/How-To: -Upgrade-to-Devise-2.1

此外,请务必通读文档以了解如何正确调整现有迁移 - https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style

于 2012-05-24T04:30:15.147 回答
13

我已经遇到了两次,并且有一个非常简单的解决方案 - 而不是 db 迁移,运行这个:

heroku run rake db:create 
# optionally with --app your_apps_name if you have multiple apps.

然后:

rake db:schema:load
于 2012-12-05T21:14:37.057 回答
8

我只是遇到了同样的问题,我更新了我的 gem,并删除了我的数据库,后来我收到了一个非常相似的消息,然后我创建了一个新的 rails 应用程序只是为了比较,结果发现迁移文件已更改,现在它包括列而不是调用方法。

我希望它有所帮助。

干杯!

于 2012-05-18T02:32:59.503 回答
4

我认为这个问题可能是由于 Devise 2.0 迁移模式样式的变化造成的。在下面的链接中查看新的架构格式。相应地更新迁移并重试。这对我来说尤其适用于#heroku

https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style

于 2013-05-31T14:38:53.717 回答
2

正如您从我的代表那里看到的那样,这个网站的新手。John Kamuchau 是正确的,您需要根据您的版本更改 xxxx_devise_create_users.rb 迁移。

例如,我刚刚将 rails 3.2 更新到 4.2 相应地更新了设计,我不得不更改已弃用的 -

t.database_authenticatable :null => false

为了 -

## Database authenticatable
t.string :email,              null: false, default: ""
t.string :encrypted_password, null: false, default: ""

老问题,但希望如果有人来找这会有所帮助。

于 2015-09-03T15:50:23.007 回答