rails 控制台中没有数据库连接 [英] No database connection in rails console
本文介绍了rails 控制台中没有数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行 rake db:migrate
时,我的 rails 应用程序工作正常,但是当我尝试启动 rails 控制台时出现问题.
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
=> User(no database connection)
推荐答案
简单的解决方案:控制台可能确实有数据库连接,但报告说没有.
simple solution: The console probably does have a database connection but is reporting that it doesn't.
要查看是否属实,请在控制台中进行查询.
To see if that's true, make a query in the console.
User.count
这为我和一位同事修复了误报警告.
That fixed the false positive warning for me and a colleague.
或
使用Model.connection
建立连接.
这篇关于rails 控制台中没有数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文