Rails 中的切换数据库阶段
-
09-12-2019 - |
题
似乎用于显示数据的数据库与我在 Rails 控制台中可以使用的数据库不同。
我尝试过跑步 rails dbconsole
我得到:
Couldn't find database client: sqlite3. Check your $PATH and try again.
我的测试和开发数据库适配器是 SQlite3,我的生产适配器是 MYSQL。
我需要我的 Rails 控制台连接到我的生产数据库。
解决方案
如果要连接到生产数据库,则需要设置 RAILS_ENV
环境变量为 production
在执行之前 console
或者 dbconsole
命令。
“Rails 控制台”和 dbconsole
命令引用不同的东西:
如果你想直接连接数据库来执行SQL语句,请使用
$ RAILS_ENV=production ./script/rails dbconsole
如果您尝试加载“Rails 控制台”,即可以访问 Rails 环境的交互式 Ruby shell,请运行
$ RAILS_ENV=production ./script/rails console
其他提示
请尝试以下命令。
RAILS_ENV=production rails c
不隶属于 StackOverflow