A Rails migration to turn a "deleted_at" time column to a datetime column failed. Any ideas on how to solve this? It's a fresh install of Postgres if that is relevant.
-- change_column(:products, :deleted_at, :datetime)
PGError: ERROR: column "deleted_at" cannot be cast to type timestamp without time zone
: ALTER TABLE "products" ALTER COLUMN "deleted_at" TYPE timestamp
In Rails this would look something like
class ChangeStatusUpdatedAtToDateTime < ActiveRecord::Migration
def up
remove_column :bookings, :status_updated_at
add_column :bookings, :status_updated_at, :datetime
end
def down
remove_column :bookings, :status_updated_at
add_column :bookings, :status_updated_at, :time
end
end
If you had data you wanted to transfer you could use the following code (not tested!):
class ChangeStatusUpdatedAtToDateTime < ActiveRecord::Migration
def up
add_column :bookings, :temp_status_updated_at, :datetime
Booking.update_all("temp_status_updated_at = updated_at")
remove_column :bookings, :status_updated_at
rename_column :bookings, :temp_status_updated_at, :status_updated_at
end
def down
add_column :bookings, :temp_status_updated_at, :time
Booking.update_all("temp_status_updated_at = updated_at")
remove_column :bookings, :status_updated_at
rename_column :bookings, :temp_status_updated_at, :status_updated_at
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With