我是Stack Overflow和Ruby on Rails的新手。我的問題是,當我運行命令rake db:create或rake db:migrate時,測試數據庫會受到影響,但是開發數據庫不會。rake db:migrate和rake db:既在測試數據庫上創建,也不在開發數據庫
軌(3.2.2)
我的database.yml:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &test
adapter: postgresql
encoding: unicode
database: ticketee_test
pool: 5
username: ticketee
password: my_password_here
development:
adapter: postgresql
encoding: unicode
database: ticketee_development
pool: 5
username: ticketee
password: my_password_here
production:
adapter: postgresql
encoding: unicode
database: ticketee_production
pool: 5
username: ticketee
password: my_password_here
cucumber:
<<: *test
感謝您的建議,但恐怕不是這個原因。我的RAILS_ENV =發展。當我啓動rails服務器時,服務器運行開發數據庫。如果我運行「rails server -e test」,那麼服務器使用測試數據庫。我仍然不確定爲什麼遷移正在我的測試數據庫上運行...
更新: 基於一個建議,我註釋掉了除開發以外的所有數據庫配置,現在出現錯誤。我正在運行postgresql,我已經安裝了gem'pg'。首先,我的新數據庫.yml:
development:
adapter: postgresql
encoding: unicode
database: ticketee_development
pool: 5
username: ticketee
password: my_password_here
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
#test: &test
# adapter: postgresql
# encoding: unicode
# database: ticketee_test
# pool: 5
# username: ticketee
# password: my_password_here
#production:
# adapter: postgresql
# encoding: unicode
# database: ticketee_production
# pool: 5
# username: ticketee
# password: my_password_here
#cucumber:
# <<: *test
我的錯誤消息!
Someguys-MacBook-Air:ticketee someguy$ rake db:migrate
rake aborted!
database configuration does not specify adapter
Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)
Someguys-MacBook-Air:ticketee someguy$ rake db:migrate -t
** 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
rake aborted!
database configuration does not specify adapter
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection'
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:23:in `spec'
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/railtie.rb:76:in `block (2 levels) in <class:Railtie>'
/Users/someguy/.rvm/gems/[email protected]/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/Users/someguy/.rvm/gems/[email protected]/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/Users/someguy/.rvm/gems/[email protected]/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
/Users/someguy/.rvm/gems/[email protected]/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:42:in `each'
/Users/someguy/.rvm/gems/[email protected]/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/base.rb:718:in `<top (required)>'
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:6:in `block (2 levels) in <top (required)>'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/someguy/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/someguy/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/someguy/.rvm/gems/[email protected]defaultGems/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/someguy/.rvm/gems/[email protected]/bin/rake:19:in `load'
/Users/someguy/.rvm/gems/[email protected]/bin/rake:19:in `<main>'
使用上面的database.yml,rake db:create:all RAN CORRECTLY並創建了我的表。但是,我的遷移仍然會失敗,並顯示與上面相同的堆棧跟蹤。
我改變了我的database.yml,以這樣的: 發展: 適配器:sqlite3的 數據庫:DB/development.sqlite3 池:5 超時:5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
更新:我完全改變了我的數據庫.yml這樣:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test: &test
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
cucumber:
<<: *test
現在,這是當我運行耙分貝會發生什麼:降:所有的,然後耙分貝:遷移。 rake db:migrate命令運行遷移,創建一個db/test.sqlite3並向其中添加一個表。所以,我的遷移仍在測試環境中運行。當我運行rake環境RAILS_ENV = development db:migrate時,同樣的事情發生,我得到一個test.sqlite3文件...
我唯一的建議是不知爲何,你在你的env中設置了RAILS_ENV = test? – 2012-03-29 17:59:34
好的建議,恐怕不是這樣。 – 2012-03-29 18:14:59
你有沒有嘗試評論一切,但發展和看到會發生什麼?可能無法正常工作,但可能會給您帶來解決方案的錯誤。 – huntsfromshadow 2012-03-29 18:24:14