I'm trying to add a array of json-objects into one of my models. Running the migration works fine, as long as I don't include a default value, but trying to store any value results in a crash. When trying to use a empty array as default value, the same crash occurs when running the migration.
My migration:
class AddJsonExampleToMyModel < ActiveRecord::Migration
def change
add_column :my_models,
:json_example
:json,
array: true,
default: []
end
end
The error looks like:
PG::InvalidTextRepresentation: ERROR: malformed array literal: "[]"
DETAIL: "[" must introduce explicitly-specified array dimensions.
: ALTER TABLE "my_models" ADD COLUMN "json_example" json[] DEFAULT '[]'/.../db/migrate/20151013125334_add_json_example_to_my_model.rb:3:in `change'
ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: malformed array literal: "[]"
DETAIL: "[" must introduce explicitly-specified array dimensions.
: ALTER TABLE "my_models" ADD COLUMN "json_example" json[] DEFAULT '[]'
/.../db/migrate/20151013125334_add_json_example_to_my_model.rb:3:in`change'
PG::InvalidTextRepresentation: ERROR: malformed array literal: "[]"
DETAIL: "[" must introduce explicitly-specified array dimensions.
Am I trying to do something that can't be done, or am I doing it incorrectly?
My setup: Rails 4.1.9, (PostgreSQL) 9.4.4, Ruby 2.1.0p0