下午好,
我在让我的数据库备份和运行时遇到了严重的问题。本周早些时候我放弃了我的桌子(想要重建)并且遇到了各种各样的问题。
我做了以下事情:
rake db:drop:all
rake db:create:all
rake db:migrate
我收到以下错误(将完整的堆栈跟踪放在底部):
PG::Error: ERROR: relation "users" does not exist
LINE 4: WHERE a.attrelid = '"users"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
Authlogic 是这里的问题。我能够看到这个错误(真正的错误)的唯一原因是因为我隐藏了 authlogic 错误:
You must establish a database connection before using acts_as_authentic
正如这篇文章中所建议的:堆栈溢出线程
用户迁移:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name, :null => false
t.string :email, :null => false
t.string :plan, :default => "basic"
t.boolean :verified, :default => false
t.boolean :admin, :default => false
t.integer :selected_portfolio_id
t.datetime :last_email_at
t.hstore :data
t.string :crypted_password, :null => false
t.string :password_salt, :null => false
t.string :persistence_token, :null => false
t.string :perishable_token, :null => false
# magic fields (all optional, see Authlogic::Session::MagicColumns)
t.integer :login_count, :null => false, :default => 0
t.integer :failed_login_count, :null => false, :default => 0
t.datetime :last_request_at
t.datetime :current_login_at
t.datetime :last_login_at
t.string :current_login_ip
t.string :last_login_ip
# optional, see Authlogic::Session::Params
#t.string :single_access_token, :null => false
t.timestamps
end
add_index :users, ["email"], :name => "index_users_on_email", :unique => true
add_index :users, ["persistence_token"], :name => "index_users_on_persistence_token", :unique => true
end
end
为什么 authlogic 试图加载数据库迁移?我假设这一定是问题....完整的堆栈跟踪:
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2. 6/lib/active_record/connection_adapters/postgresql_adapter.rb:1151:in `async_exec'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2. 6/lib/active_record/connection_adapters/postgresql_adapter.rb:1151:in `exec_no_cache'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2. 6/lib/active_record/connection_adapters/postgresql_adapter.rb:664:in `block in exec_query'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2. 6/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/notifications/instrumenter. rb:20:in `instrument'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2. 6/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2. 6/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in `exec_query'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2. 6/lib/active_record/connection_adapters/postgresql_adapter.rb:1276:in `column_definitions'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2. 6/lib/active_record/connection_adapters/postgresql_adapter.rb:859:in `columns'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2. 6/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:228:in `yield'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:228:in `default'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:228:in `columns'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:248:in `column_names'
/Users/brandon/Documents/authlogic/lib/authlogic/acts_as_authentic/base.rb:67:in `db_setup?'
/Users/brandon/Documents/authlogic/lib/authlogic/acts_as_authentic/base.rb:31:in `acts_as_authentic'
/Users/brandon/Dropbox/code/myapp/app/models/user_related/user.rb:14:in `<class:User>'
/Users/brandon/Dropbox/code/myapp/app/models/user_related/user.rb:1:in `<top (required)>'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:469:in `load'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:469:in `block in load_file'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:639:in `new_constants_in'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:468:in `load_file'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:353:in `require_or_load'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:502:in `load_missing_constant'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:192:in `block in const_missing'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in `each'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in `const_missing'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/inflector/methods.rb:229:in `block in constantize'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/inflector/methods.rb:228:in `each'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/inflector/methods.rb:228:in `constantize'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/core_ext/string/inflections. rb:54:in `constantize'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activemodel-3.2.6/lib/active_model/observing.rb:189:in `block in observe'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activemodel-3.2.6/lib/active_model/observing.rb:189:in `collect!'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activemodel-3.2.6/lib/active_model/observing.rb:189:in `observe'
/Users/brandon/Dropbox/code/myapp/app/models/user_related/user_observer.rb:2:in `<class:UserObserver>'
/Users/brandon/Dropbox/code/myapp/app/models/user_related/user_observer.rb:1:in `<top (required)>'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:469:in `load'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:469:in `block in load_file'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:639:in `new_constants_in'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:468:in `load_file'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:353:in `require_or_load'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:502:in `load_missing_constant'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:192:in `block in const_missing'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in `each'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in `const_missing'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/inflector/methods.rb:229:in `block in constantize'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/inflector/methods.rb:228:in `each'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/inflector/methods.rb:228:in `constantize'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/core_ext/string/inflections. rb:54:in `constantize'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activemodel-3.2.6/lib/active_model/observing.rb:86:in `instantiate_observer'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activemodel-3.2.6/lib/active_model/observing.rb:59:in `block in instantiate_observers'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activemodel-3.2.6/lib/active_model/observing.rb:59:in `each'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activemodel-3.2.6/lib/active_model/observing.rb:59:in `instantiate_observers'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/railtie.rb:117:in `block (2 levels) in <class:Railtie>'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:26:in `block in on_load'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:25:in `each'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:25:in `on_load'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/railtie.rb:116:in `block in < class:Railtie>'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:34:in `call'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:42:in `each'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/application/finisher.rb:59:in `block in < module:Finisher>'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `instance_exec'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `run'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `each'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `run_initializers'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/application.rb:136:in `initialize!'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/brandon/Dropbox/code/myapp/config/environment.rb:5:in `<top (required)>'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/application.rb:103:in `require_environment!'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/brandon/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/brandon/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `load'
/Users/brandon/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `<main>'
Tasks: TOP => db:migrate => environment
更新 1
我能够通过注释掉“行为真实”,迁移数据库,然后重新应用来解决这个问题。虽然它是创可贴,但它似乎并不正确。我该如何正确解决这个问题?