This creates an array of strings whose default is an empty array:
t.string :A_options, array: true, default: []
This creates an array of integers whose default is an empty array:
t.integer :A_options, array: true, default: []
This should be a NoMethodError
:
t.array :A_options
There is no "array" type in PostgreSQL, only "array of X" where "X" is some other column type. PostgreSQL arrays aren't generic containers like Ruby arrays, they're more like arrays in C, C++, Go, ...
If you need a generic container that's more like a Ruby array then perhaps you want jsonb
instead. A jsonb
array could hold a collection of numbers, strings, booleans, arrays, hashes, ... at the same time.
As far as the generator goes, you can't specify default: []
because you can't specify the default
at all:
3.5 Column Modifiers
[...]
null
and default
cannot be specified via command line.
Also see Can I pass default value to rails generate migration?.