Rails: Migration to change PostgreSQL column to timestamp with timezone
Appearance
Rails: Migration to change PostgreSQL column to timestamp with timezone
Problem
Rails creates a datetime column as 'timestamp without time zone' by default. I would like the column type to be 'timestamp with time zone'.
Environment
- Rail-6
- Postgresql-10
Solution
Create a migration via rails g migration and use this command in the def change method:
change_column :rooms, :start_time, 'timestamptz using start_time::timestamptz'See: https://stackoverflow.com/questions/31727203/rails-migration-to-postgres-issue-time#answer-40160685