Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails database complain non exist on production only (with db:migrate succeeded)

Setup

Gemfile:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
gem 'dotenv-rails', :require => 'dotenv/rails-now'
# Use PostgreSQL as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

gem 'sprockets-rails', '2.3.3'

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# use puma as app server
gem 'puma'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  # conflict in RubyMine
  gem 'byebug'
  gem 'sqlite3'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'

  # generate ERD
  gem 'rails-erd'

  gem 'guard', '>= 2.2.2', :require => false
  gem 'guard-minitest', :require => false
  gem 'letter_opener'
end

group :test do
  gem 'minitest-reporters'
  gem 'minitest-spec-rails'
  gem 'resque_unit'
end

gem 'interactor-rails', '~> 2.0'
gem 'dotenv'
gem 'ooor'
gem 'resque'
gem 'resque-retry'
gem 'resque-logger'
gem 'resque-history'
gem 'resque-scheduler' 
gem 'resque-web', require: 'resque_web'
gem 'resque-scheduler-web'
gem 'net-sftp'
gem 'nokogiri'
gem 'rubyzip'
gem 'aws-sdk'

gem 'resque_mailer'

database.yml:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

test:
  <<: *default
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

staging:
  <<: *default
  database: <%= ENV['DATABASE_NAME'] %>
  username: <%= ENV['DATABASE_USER'] %>
  password: <%= ENV['DATABASE_PASSWORD'] %>

production:
  <<: *default
  database: <%= ENV['DATABASE_NAME'] %>
  username: <%= ENV['DATABASE_USER'] %>
  password: <%= ENV['DATABASE_PASSWORD'] %>

.env.production:

DATABASE_NAME='rapid_tunnel_production'

The Problem

  1. When I do: RAILS_ENV=production rake db:create db:migrate, it works perfectly fine

  2. When I do: rails s -e production, in log/production.log, I have error:

    I, [2016-05-03T15:50:47.819743 #4932]  INFO -- : Started GET "/favicon.ico" for ::1 at 2016-05-03 15:50:47 +0800
    F, [2016-05-03T15:50:47.825279 #4932] FATAL -- :
    ActiveRecord::NoDatabaseError (FATAL:  database "rapid_tunnel_production" does not exist
    ):
      activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:661:in `rescue in connect'
      activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
      activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
      activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
      activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
      activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
      activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
      activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
      activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
      /Users/songyy/.rvm/rubies/ruby-head/lib/ruby/2.3.0/monitor.rb:211:in `mon_synchronize'
      activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
      activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
      /Users/songyy/.rvm/rubies/ruby-head/lib/ruby/2.3.0/monitor.rb:211:in `mon_synchronize'
      activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
      activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
      activerecord (4.2.6) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
      activerecord (4.2.6) lib/active_record/connection_handling.rb:87:in `connection'
      activerecord (4.2.6) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings'
    

Question

Any idea why this happens?

like image 230
songyy Avatar asked Jan 17 '26 19:01

songyy


1 Answers

it could be due to spring preloader. try disable sprint preloader by setting DISABLE_SPRING and try db:setup again.

like image 68
leyonh Avatar answered Jan 20 '26 10:01

leyonh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!