Rails app confused about environment?
I created a new Ruby on Rails app (first app I'm working on in Rails 3), and for some reason, my app seems to be confused about what environment it should be running in (unless I'm just confused).
When I run rake db:create
, it's creating both the "myapp_development" and "myapp_test" databases. When I subsequently run rake db:drop
, it drops the development database, but not the test database.
What's going on?
Edit 1: Here's what my database.yml file looks like:
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:
Edit 2: Tried recreating a new app from scratch, and still have the same issue. Here's what I did.
1. Created a new rails app:
rails new myapp
2. Edited my 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. Edited my 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. Running rake db:create
at this point creates both myapp_development
and myapp_test
. If I proceed to run rake db:drop
followed by rake db:create
, I get a command line warning stating "myapp_test already exists" since the drop only removes myapp_development
, but the create attempts to create both dev and test databases.
It would only create the development and test databases if you ran rake db:create:all
, not rake db:create
. The latter will only create one or the other, depending on the environment you're working in.
check your
config/database.yml
file in your app for the database configuration, you probably want test around though. but database.yml will let you access everything. It will use the development db by default though then you specify when to use production
Also a note, just running rake db:migrate
will create the databases if they don't exist and migrate your models, you might want to use that instead
精彩评论