Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4231358
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T01:57:39+00:00 2026-05-21T01:57:39+00:00

I have a table with dates stored as unix timestamps (ints). I want my

  • 0

I have a table with dates stored as unix timestamps (ints). I want my migration to move these ints to another column, change the type of the first column to datetime, then convert the ints to ruby times and stick them back in the first column. This is my migration:

def self.up
    add_column :events, :start_date_int, :int
    Event.all.each do |event|
        event.start_date_int = event.start_date
        event.save
    end
    change_column :events, :start_date, :datetime

    Event.all.each do |event|
    time = Time.at(event.start_date_int)    
        event.start_date = time
        puts time
        puts event.start_date
        event.save
    end
end

The terminal output is this:

==  DatesToDates: migrating ===================================================
-- add_column(:events, :start_int, :int)
-> 0.2880s
-- add_column(:events, :end_int, :int)
-> 0.3138s
-- change_column(:events, :start, :datetime)
-> 0.2695s
-- change_column(:events, :end, :datetime)
-> 0.2959s
Sun May 01 13:00:00 -0400 2011
1304269200
==  DatesToDates: migrated (1.2923s) ==========================================

(There is only 1 event in the development DB)

For some reason event.start_date = time trying to stick the int into event.start_date instead of the converted time. If I separate the second loop into another migration and run the two seperately (via db:migrate:up VERSION=X for each) everything works properly, but if both migrations run together via a normal db:migrate, even if they are in separate files, it fails as stated. Any ideas?

(This is rails 3 with MySQL)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T01:57:40+00:00Added an answer on May 21, 2026 at 1:57 am

    You probably want to have a look at reset_column_information. I’m guessing this is your issue since you mention that it works if you do the migrations separately, but not when run together.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with 5 million records of dates stored as char(10) with
I have one table which contains events and dates, and another which contains the
I have to fix a table where date and time are stored as unix
I have the dates stored in a mySQL table from 2010 - 2040 in
I have a date column with dates stored as strings, such as 20120817. Unfortunately,
I have a Mysql table that stores dates in the format (YYYY-MM-DD HH:MM:SS). What
I have a table in sql where the date format is stored in Hijri.
I have a table, tblClient , which stored a client's date of birth in
i have a table in mysql db ( created_date). It stores timestamps (INT value).
I have a table of increasing dates (with gaps) and corresponding values date |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.