Tôi mới vào Stack Overflow và Ruby on Rails. Vấn đề của tôi là, khi tôi chạy lệnh rake db: tạo hoặc rake db: di chuyển, cơ sở dữ liệu thử nghiệm bị ảnh hưởng, nhưng cơ sở dữ liệu phát triển thì không.rake db: di chuyển và rake db: tạo cả hai công việc trên cơ sở dữ liệu thử nghiệm, không phải cơ sở dữ liệu phát triển
ray (3.2.2)
database.yml của tôi:
# 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
Cảm ơn đã gợi ý, nhưng tôi sợ rằng không phải là lý do. RAILS_ENV của tôi = phát triển. Khi tôi khởi động máy chủ đường ray, máy chủ sẽ chạy cơ sở dữ liệu phát triển. nếu tôi chạy "rails server -e test" thì máy chủ sử dụng cơ sở dữ liệu thử nghiệm. Tôi vẫn không chắc tại sao di chuyển đang chạy trên cơ sở dữ liệu thử nghiệm của tôi ...
CẬP NHẬT: Dựa trên đề xuất, tôi nhận xét tất cả các cấu hình cơ sở ngoại trừ phát triển và bây giờ tôi gặp lỗi. Tôi đang chạy postgresql, tôi đã cài đặt gem 'pg'. Đầu tiên, database.yml mới của tôi:
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
Thông báo lỗi của tôi!
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/ruby-1.9.3-p125[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]/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>'
Sử dụng cơ sở dữ liệu.yml ở trên, rake db: create: all RAN CORRECTLY và tạo bảng của tôi. Tuy nhiên, quá trình di chuyển của tôi vẫn không thành công với dấu vết ngăn xếp giống như ở trên.
tôi đã thay đổi database.yml của tôi như thế này: phát triển: adapter: sqlite3 cơ sở dữ liệu: db/development.sqlite3 hồ bơi: 5 timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
UPDATE: Tôi hoàn toàn thay đổi cơ sở dữ liệu của tôi .yml cho điều này:
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
Bây giờ, đây là những gì xảy ra khi tôi chạy rake db: drop: all, theo sau bởi rake db: migrate. Lệnh rake db: migrate chạy một quá trình di chuyển, tạo ra một db/test.sqlite3 AND thêm một bảng vào đó. Vì vậy, quá trình di chuyển của tôi vẫn đang chạy trên môi trường thử nghiệm. Khi tôi chạy môi trường rake RAILS_ENV = phát triển db: di chuyển, cùng một điều xảy ra và tôi nhận được tệp test.sqlite3 ...
gợi ý duy nhất của tôi là bằng cách nào đó bạn đã đặt RAILS_ENV = test trong env của bạn chưa? –
Đề nghị tốt, tôi e rằng đó không phải là nó mặc dù. –
Bạn đã thử bình luận mọi thứ nhưng phát triển và thấy điều gì sẽ xảy ra? Có thể không hoạt động nhưng có thể cung cấp cho bạn một lỗi dẫn đến giải pháp. – huntsfromshadow