I converted a MySQL database to PostgreSQL in a Rails app, and the MySQL double column was converted to a double precision column in PostgreSQL.
The problem is that even if the PostgreSQL structure has this column with a default value of "0::double precision", rake db:schema:dump does not add this default value.
Therefore, when a model instance is created, the default value is not auto-assigned, and instead its value is nil.
Now, I'm on Rails 4.1.6, and this happens because the column type is not listed here (AFAIK). What is strange (to me) is why this hasn't been added yet.
What could be the recommended approach here? Change the column type in PostgreSQL?
A \d payments from inside psql says:
Table "public.payments"
Column | Type | Modifiers
----------------+-----------------------------+-------------------------------------------------------
id | integer | not null default nextval('payments_id_seq'::regclass)
credit_card_id | integer | not null default 0
order_id | integer | not null default 0
amount | double precision | not null default 0::double precision
created_at | timestamp without time zone | not null
updated_at | timestamp without time zone | not null
authorization | character varying(510) | default NULL::character varying
Indexes:
"payments_pkey" PRIMARY KEY, btree (id)
"credit_card_id" btree (credit_card_id)
"purchase_order_id_1" btree (order_id)
and the corresponding section of schema.rb says:
create_table "payments", force: true do |t|
t.integer "credit_card_id", default: 0, null: false
t.integer "order_id", default: 0, null: false
t.float "amount", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "authorization", limit: 510
end
psqlfrom the command line and\d table_name. What does the table look like inschema.rb?amount.