【发布时间】:2011-08-05 05:52:39
【问题描述】:
我创建了一个新的 Ruby on Rails 应用程序(我在 Rails 3 中开发的第一个应用程序),出于某种原因,我的应用程序似乎对它应该在什么环境中运行感到困惑(除非我只是困惑)。
当我运行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 会同时创建 myapp_development 和 myapp_test。如果我继续运行rake db:drop,然后运行rake db:create,我会收到一条命令行警告,指出“myapp_test 已存在”,因为删除只删除了myapp_development,但创建尝试创建开发和测试数据库。
【问题讨论】:
-
我面临着完全相同的问题。我正在运行 rake db:create 和 rails 创建开发和测试模式。当我运行 rake db:drop 时,它只删除开发模式。这肯定是一个环境配置问题,因为它在一台机器(macos 雪豹)上正常工作,但在我的新机器(macos lion)上却不行。我仍在尝试找出可能导致此行为的两台机器的环境之间的差异。任何提示表示赞赏。如果我发现了什么会发布。
-
我从来没有找到解决这个问题的方法,所以如果你能解决的话,我会很高兴听到的!
标签: ruby-on-rails ruby-on-rails-3 configuration