Rake db: migrate and rake db: create and work with a test database, not with a development database

I am new to Qaru and Ruby on Rails. My problem is that when I run the rake db: create or rake db: migrate command, the test database is affected, but the development database is not.

rails (3.2.2)

my 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 

Thanks for the offer, but I'm afraid that is not the reason. My RAILS_ENV = development. When I start the rails server, the server starts the development database. if I run "rails server -e test" then the server uses the test database. I'm still not sure that migrations are performed in my test database ...

UPDATE: Based on the assumption, I commented on all database configurations except development, and now I get an error. I run postgresql, I have gem 'pg' installed. Firstly, my new database.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 

My error message!

 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/ ruby-1.9.3-p125@defaultGems /gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:23:in `spec' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/activerecord-3.2.2/lib/active_record/railtie.rb:76:in `block (2 levels) in <class:Railtie>' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:42:in `each' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /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@defaultGems /gems/activerecord-3.2.2/lib/active_record/base.rb:718:in `<top (required)>' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:6:in `block (2 levels) in <top (required)>' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /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/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /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/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /bin/rake:19:in `load' /Users/someguy/.rvm/gems/ ruby-1.9.3-p125@defaultGems /bin/rake:19:in `<main>' 

Using database.yml above, rake db: create: all RAN CORRECTLY and created my table. However, my migration still fails with the same stack trace as the previous one.

I changed my database.yml to this: development: adapter: sqlite3 database: db / development.sqlite3 pool: 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: I completely changed my database.yml to this:

 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 

Now this is what happens when I run rake db: drop: all, followed by rake db: migrate. The rake db: migrate command performs the migration, creating db / test.sqlite3 and adding a table to it. So my migration is still working in a test environment. When I run the rake RAILS_ENV = development db: migrate environment, the same thing happens and I get the file test.sqlite3 ...

+7
source share
6 answers

I had the same problem starting last night. I donโ€™t know what could have caused this, but finally found a solution that worked. Inside the configure block in config / environment / develop.rb, I added:

 Rails.env = 'development' 

I hope this works for you too.

+2
source

There is a โ€œbrilliantโ€ line in ActiveRecord / Library / active_record / tasks / database_tasks.rb:

 environments << 'test' if environment == 'development' && ENV['RAILS_ENV'].nil? 

which before jan 8, 2014 looked like this:

 environments << 'test' if environment == 'development' 
+3
source

It looks like your decision could be related to several things. Your environment may have confused migration due to existing elements. Reset your database using:

 rake db:reset 

or

 rake db:drop db:create 

depending on your environment, you should be able to migrate.

 rake db:migrate 

PS - You may need to add bundle exec at the beginning of each command.

Good luck.

+2
source

You are missing host: localhost in your yml file.

Change the configuration as follows:

 development: adapter: postgresql encoding: unicode host: localhost database: ticketee_development pool: 5 username: ticketee password: my_password_here 
0
source

Fork Error! Perhaps some problems with caching or logging. This shows that nothing is happening in our code.

My team resolves this.

  • delete project

  • git clone project

  • config database.yml

  • start server

Everything is good!

Errors have disappeared in the same project! Therefore, we believe that these are problems with env or cach or log.

0
source

You can use rake db: migrate RAILS_ENV = "development"

or you can use as

set RAILS_ENV = development

rake db: migrate

0
source

All Articles