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 1018861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:55:18+00:00 2026-05-16T10:55:18+00:00

Is it possible to change a field that’s a string to an integer without

  • 0

Is it possible to change a field that’s a string to an integer without clearing the data already entered?

The current db structure for the table in question is:

create_table :people do |t|
t.string :company_id

Is this possible using migrations?

I’m thinking maybe in the migration drop the old field, create a new one that’s an integer – but I’m worried this will clear all of the data already entered.

Thanks,

Danny

  • 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-16T10:55:19+00:00Added an answer on May 16, 2026 at 10:55 am

    Do not drop the column, it will clear the data.

    You can however try

    change_column :people, :company_id, :integer
    

    and if all values in company_id can be converted to integer, it should be fine.

    If that is not the case (ie not all string can be converted by default), then you can do it in two steps: 1) create a new column, then load the company_id in there after some conversion. 2) drop company_id then rename the new column.

    You should be careful with both methods (more so for the second one) and you should probably do it first on a copy of the database, if you can.

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

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No regexp required. Dim r As String = "potato".Replace('o', '0')… May 16, 2026 at 1:59 pm
  • Editorial Team
    Editorial Team added an answer This is not possible due to how most clients implement… May 16, 2026 at 1:59 pm
  • Editorial Team
    Editorial Team added an answer You might consider creating a web application that connects to… May 16, 2026 at 1:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Is it possible to change the natural order of columns in Postgres 8.1? I
I have a text input field that has some sample text in a light
Sometimes users require to change information in SharePoint list item that is not editable
I have a few SQL Server tables with a datetime field that really only
This is a follow-up on How do you change the default widget for all
(Note: updated with adopted answer below.) For a PostgreSQL 8.1 (or later) partitioned table,
There are following object: 'FieldItem' custom control; 'Field' - ... XAML-object, which will contains
I have a profile weblog that contains all our users details (fields seperate from
I need to compare 2 strings as equal such as these: Lubeck == Lübeck
I am using GUIDs as my primary key for all my other tables, but

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.