25

我使用Active Admin gem爲我的基於測驗的小應用程序。但是當我執行rake db:migrate它給了我錯誤。以下是命令的痕跡:未定義的方法`database_authenticatable'爲#<ActiveRecord :: ConnectionAdapters :: TableDefinition:0x9dee690>

$ 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 

Follwoing是我的Gemfile:

內容 20120509055635_devise_create_admin_users.rb
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' 

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 => '[email protected]', :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 

我搜索了上述問題,並得到了this,但這並沒有幫助我。我到處都找到了這個解決方案。 以前有沒有人遇到過這個問題,如果是的話,你做了什麼來解決它?任何幫助,將不勝感激。謝謝

回答

7

我剛剛有我認爲是同樣的問題,我更新了我的寶石,並放棄了我的分貝,後來我得到了一個非常類似的消息,然後我創建了一個新的Rails應用程序只是爲了比較,結果證明遷移文件已被更改,現在它包括列而不是調用方法。

我希望它有幫助。

乾杯!

+0

謝謝你。得到了那個工作。這同樣是問題,遷移文件具有列名稱而不是設計方法名稱。 – lucifer

+0

您能否將遷移代碼放在這個答案中。 – baash05

43

當我嘗試部署到新的登臺服務器時,我也在我現有的應用程序中遇到了此問題。

最終發現Devise gem已經更新到2.1,並且我還沒有修復遷移到新版本的正確工作。

一定要通過遷移到閱讀到2.1 DOC自己的維基 - 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

+1

+1感謝您的鏈接。 – abhijit

+0

沒問題,很高興幫助! –

12

我已經碰上這兩次,有一個非常簡單的解決方案 - 而不是數據庫遷移,運行這個命令:

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

則:

rake db:schema:load 
+0

rake db:create rake db:schema:load 這兩個命令對我很有用。 –

+0

這使得遷移中斷。可能不是一個好主意。 – eagspoo

+0

什麼時候會成爲問題? – Jwan622

1

新來這個網站,你可以從我的代表處看到。 John Kamuchau是正確的,您需要根據您的版本更改xxxx_devise_create_users.rb遷移。

例如我剛更新了一個導軌3.2到4。2更新相應的設計,我不得不改變了過時 -

t.database_authenticatable :null => false 

爲 -

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

老問題,但希望這可以幫助,如果有人來尋找。

相關問題