我在 RestAPI 的創建程序中使用 Ruby on Rails,我使用以下命令創建應用程式:
rails _6.1.5_ new myproject --api
現在我需要在專案中添加資料庫支持,特別是我需要使用PostgreSQL,到目前為止我找到了這個引數但是對于新專案:
rails _6.1.5_ new myproject --api --database=postgresql
我的問題是:有沒有辦法(引數,命令?)為我現有的專案添加 postgresql 支持?
非常感謝
uj5u.com熱心網友回復:
如果您想從 sqlite 更改為 postgresql 很簡單,只需添加gem 'pg'到 Gemfile,然后捆綁安裝,然后將您的默認部分更改database.yml為:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/487403.html
標籤:轨道上的红宝石 PostgreSQL 休息
上一篇:面對ActiveRecord::NotNullViolation例外:PG::NotNullViolation:錯誤:“item_id”列中的空值違反非空約束
