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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:53:56+00:00 2026-06-15T23:53:56+00:00

Say in Rails 3, you have a model User and hence its table is

  • 0

Say in Rails 3, you have a model User and hence its table is called :users

Something went horribly wrong and you need to drop the table but you cannot since you have other references to the user_id. So you need to clear your users table schema.

Basically what you need is a way to drop all columns.

If your table has more than 40 columns, you can forget the style

remove_column :users, :col1

You need to do it all at once. In one migration

  • 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-06-15T23:53:57+00:00Added an answer on June 15, 2026 at 11:53 pm

    Assuming you have generated a blank migration using

    rails g migration PurgeOldUsersSchema

    So this is how your migration should look like

    class PurgeOldUsersSchema < ActiveRecord::Migration
      def change
        cols = []
        User.columns.collect(&:name).each do |col|
         cols.push(col.to_sym)
        end
        cols = cols - [:id]
        remove_column :users, cols
      end
    end
    

    Keep in mind the - [:id] is necessary since rails cannot allow you to drop the primary key. In this array you can add any column name you want to preserve post the purge op.

    This keeps your references to this table intact in the schema, but you would anyway purge the data, so that is not much relevant. 🙂

    UPDATE

    Have tried this solution but remove_column :users, cols didn’t work for me so I had to replace it with:

    cols.each { |col| remove_column :users, col }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model in rails, lets say User , which i want to
I have a rails model let say User with a has many relationship with
I'm using Rails 3 with Devise for user auth. Let's say I have a
Say I have a model User which has_many Post children. Obviously I can access
In my Rails application I have a User model ,Department model, Group model and
(Disclaimer: New to Rails here) Say I have a Rails ActiveRecord Model that responds
I have a user model that has many fields (let's say 30 for this
I'm using codebrew\backbone-rails in a nested model example (say I have a collection of
Let's say I have a User model which has_many :posts , while Post has_many
I have the following simple problem with rails. Let say I have a model

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.