I made a Posts model in Rails API with a field "vouches". I want that field to default to an empty array. This works just fine locally. Here is the relevant schema.rb:
ActiveRecord::Schema.define(version: 2020_06_09_164230) do
enable_extension "plpgsql"
create_table "posts", force: :cascade do |t|
t.string "title"
t.text "description"
t.string "image"
t.integer "vouches", default: [], array: true
end
end
Locally this works great. When I create a new Post, locally my endpoint for fetching the data shows as such:
{
"id":1,
"title":"test",
"description":"test",
"image":null,
"vouches":[]
}
I deployed my app to Heroku, ran migrations. If I make the exact same post on the deployed site I get the following:
{
"id":1,
"title":"test",
"description":"test",
"image":null,
"vouches":null
}
I tried making a before_create method on the Post model that made self.vouches ||= [], to no avail. Having trouble finding other solutions that are relevant to this situation. I'm assuming this is a Postgres issue - but maybe I'm wrong on that front.