No database connection in rails console

后端 未结 4 438
春和景丽
春和景丽 2021-02-01 13:37

My rails application works fine when I run rake db:migrate but the problem occurs when I try to start the rails console.

2.0.0p247 :003 > User
 =         


        
4条回答
  •  日久生厌
    2021-02-01 13:56

    That is due to ActiveRecord establishing the connection lazily starting 4.0. Just don't worry about it.

    After it's established the first time, you'll start seeing the expected output. Try this:

    2.1.4 :001 > User
    # => User (call 'User.connection' to establish a connection)
    
    2.1.4 :001 > User.count
    # => SELECT COUNT(*) FROM "users" ...
    
    2.1.4 :001 > User
    # => User(id: integer, email: string, encrypted_password: string, ...)
    

提交回复
热议问题