0

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.

Tennyx
  • 153
  • 10
  • Can you add the table schema dump from Heroku Postgres as well (i.e., run ``heroku pg:psql`` and do ``\d ``)?
    – rmlockerd Jun 26 '20 at 19:04
  • it returned: ERROR: column c.relhasoids does not exist LINE 1: ...riggers, c.relrowsecurity, c.relforcerowsecurity, c.relhasoi... – Tennyx Jun 26 '20 at 20:21
  • A quick google indicates that is a mismatch between the server and ``psql`` client versions (https://stackoverflow.com/questions/58461178/how-to-fix-error-column-c-relhasoids-does-not-exist-in-postgres). I initially thought maybe the default (``'{}'::text[]``) was somehow not set on the table, but if you can't even set the attribute to an empty array that's puzzling. Out of curiosity, what happens if you set ``vouches`` to some non-array value like a String? – rmlockerd Jun 26 '20 at 21:24

0 Answers0