2

I just ran rake db:migrate successfully on Heroku on my first deploy of my Rails 4 app:

$ heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.7124
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
Migrating to DeviseCreateUsers (20131223210005)
==  DeviseCreateUsers: migrating ==============================================
-- create_table(:users)
   -> 0.0431s
-- add_index(:users, :email, {:unique=>true})
   -> 0.0093s
-- add_index(:users, :reset_password_token, {:unique=>true})
   -> 0.0185s
==  DeviseCreateUsers: migrated (0.0716s) =====================================

Migrating to AddNameToUsers (20131223210006)
==  AddNameToUsers: migrating =================================================
-- add_column(:users, :name, :string)
   -> 0.0060s
==  AddNameToUsers: migrated (0.0062s) ========================================

Migrating to AddConfirmableToUsers (20131223210008)
==  AddConfirmableToUsers: migrating ==========================================
-- add_column(:users, :confirmation_token, :string)
   -> 0.0030s
-- add_column(:users, :confirmed_at, :datetime)
   -> 0.0016s
-- add_column(:users, :confirmation_sent_at, :datetime)
   -> 0.0018s
-- add_column(:users, :unconfirmed_email, :string)
   -> 0.0016s
==  AddConfirmableToUsers: migrated (0.0085s) =================================

Migrating to RolifyCreateRoles (20131223210011)
==  RolifyCreateRoles: migrating ==============================================
-- create_table(:roles)
   -> 0.0139s
-- create_table(:users_roles, {:id=>false})
   -> 0.0021s
-- add_index(:roles, :name)
   -> 0.0093s
-- add_index(:roles, [:name, :resource_type, :resource_id])
   -> 0.0143s
-- add_index(:users_roles, [:user_id, :role_id])
   -> 0.0095s
==  RolifyCreateRoles: migrated (0.0502s) =====================================

Now when I go to the console - heroku run console and try to access any of the models I get a no database connection message.

$ heroku run console
Running `console` attached to terminal... up, run.9633
Loading production environment (Rails 4.0.2)
irb(main):001:0> User
=> User(no database connection)
irb(main):002:0> User
=> User(no database connection)
irb(main):003:0> exit

This is the concatenated version (for brevity) of my Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.0.2'
gem 'sass-rails', '~> 4.0.0'
gem 'cancan'
gem 'devise'
gem 'pg'
gem 'rolify'
gem 'thin'
gem "rails_admin"
gem "friendly_id"

group :development do
  gem 'better_errors'
  gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
  gem 'quiet_assets'
  gem 'rails_layout'  
  gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
  gem 'sextant'
end

group :production do
  gem "rails_12factor"  
end

ruby '2.0.0'

My database.yml file:

# PostgreSQL. Versions 8.2 and up are supported.
#
development:
  adapter:  postgresql
  host:     localhost
  encoding: unicode
  database: mydbname
  pool:     5
  username: myusername
  password:
  template: template0

test:
  adapter:  postgresql
  host:     localhost
  encoding: unicode
  database: my_test_db
  pool:     5
  username: myusername
  password:
  template: template0

production:
  adapter:  postgresql
  host:     localhost
  encoding: unicode
  database: myproductiondb
  pool:     5
  password:
  template: template0

Not sure what's happening.

1 Answer 1

5

no database connection in the console doesn't mean the connection is failing. It simply means that Rails hasn't connected to the database (yet) probably because there was no need.

You can see if the connection works by trying to perform a query. For instance

User.all

and see if it raises any error.

In order to see the attributes, you can trigger inspect explicitly on the model

User.inspect
Sign up to request clarification or add additional context in comments.

2 Comments

Ahhh....ok....well I am used to seeing the AR object when I do User in Rails 3.x. How do I see that now? User.all works....btw. i.e. I want to see all the attributes of a User object. How do I do that now?
User.inspect should trigger it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.