轨道开关数据库

Kev*_*vin 6 mysql sqlite postgresql ruby-on-rails

我找到了解释如何从一开始就使用 PostgreSQL 数据库设置 Rails 应用程序的信息。但我已经构建了一个应用程序。关于将我现有的应用程序更改为使用 PostgreSQL 而不是 SQLite 的步骤有什么建议吗?

Emm*_*uel 9

如果您使用的是 Rails 6+,您可以执行以下操作:

rails db:system:change --to=postgresql

postgresql你想要的数据库在哪里。

这是通过此提交启用的。


And*_*lin 3

在 Gemfile 中安装 pg gem

宝石'pg'

更改database.yml 文件以使用您的数据库ex。

adapter: postgresql
database: db_name
pool:
timeout:
host: localhost
username: username
password: password
Run Code Online (Sandbox Code Playgroud)

db_name、用户名和密码值也是您为 postgresql 数据库设置的值