我創建了一個新的Ruby on Rails應用程序(我在Rails 3中開發的第一個應用程序),出於某種原因,我的應用程序似乎對應該運行的環境感到困惑(除非我感到困惑) 。Rails應用程序對環境感到困惑嗎?
當我運行rake db:create
時,它創建了「myapp_development」和「myapp_test」數據庫。當我隨後運行rake db:drop
時,它將刪除開發數據庫,但不會刪除測試數據庫。
發生了什麼事?
編輯1:這是我的database.yml文件中是什麼樣子:
development:
adapter: mysql
database: myapp_development
username: root
password:
# 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:
adapter: mysql
database: myapp_test
username: root
password:
production:
adapter: mysql
database: myapp_production
username: root
password:
編輯2:試圖從頭開始重新創建一個新的應用,仍然有同樣的問題。這就是我所做的。
1.創建一個新的Rails應用程序:
rails new myapp
2.編輯我的Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.6'
gem 'mysql', '2.8.1'
# Bundle the extra gems:
gem 'warden', '1.0.3'
gem 'devise', '1.2.1'
gem 'geokit'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development, :test do
gem 'ruby-debug'
end
3.編輯我的database.yml:
development:
adapter: mysql
database: myapp_development
username: root
password:
host: localhost
# 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:
adapter: mysql
database: myapp_test
username: root
password:
host: localhost
production:
adapter: mysql
database: myapp_production
username: root
password:
host: localhost
4.在此處運行rake db:create
oint創建myapp_development
和myapp_test
。如果我繼續運行rake db:drop
,然後運行rake db:create
,則會收到命令行警告,指出「myapp_test已存在」,因爲該刪除僅刪除myapp_development
,但創建嘗試同時創建開發和測試數據庫。
我面對完全相同的問題。我正在運行rake db:create和rails創建開發和測試模式。當我運行rake db:drop時,它只會刪除開發模式。 這當然是一個環境配置問題,因爲它在一臺機器(macos雪豹)中正常工作,但不在我的新機器(macos獅子)上。我仍然試圖弄清楚兩臺機器的可能導致此行爲的envs之間的差異。任何提示表示讚賞。將發佈,如果我找到了什麼。 – 2012-03-07 19:54:19
我從來沒有找到一個解決方案,所以我很高興聽到,如果你弄明白了! – 2012-03-07 21:37:41