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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:59:09+00:00 2026-05-14T16:59:09+00:00

How do I drop selected tables in Rails? I want to drop all tables

  • 0

How do I drop selected tables in Rails? I want to drop all tables from a database with a given prefix. PHPMyAdmin would be very useful at this point.

Thanks

  • 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-14T16:59:09+00:00Added an answer on May 14, 2026 at 4:59 pm

    You could install phpMyAdmin and manually delete your tables, or if you wanted to do it from within the rails framework and keep you migrations in sync, why not create a new migration that drops the tables on self.up and creates the tables on self.down.

    class DropOldTablesMigration < ActiveRecord::Migration
      def self.up
        drop_table :prefix_table1
        drop_table :prefix_table2
      end
    
      def self.down
        create_table :prefix_table1 do |t|
          t.column :name, :string
        end
        create_table :prefix_table2 do |t|
          t.column :name, :string
        end
      end
    end
    

    EDIT:
    Just to follow up, if the issue is that there are a lot of tables and you don’t want to type them all, you could do something like this:

    class DropOldTablesMigration < ActiveRecord::Migration
      def self.up
        ActiveRecord::Base.connection.tables.each do |t|
          unless t.index('yourprefix_') == nil
            drop_table t
          end
        end
      end
    end
    

    Of course you would not be able to recreate the tables when you migrate down that way, but depending on what is going on in your app, that may not be a concern.


    EDIT IN RESPONSE TO YOUR COMMENT:

    To create a new migration, from the root of your app run the following command:

    script/generate migration YourMigrationName
    

    The migration file will be created for you in db/migrate. Add the code you want to run and save it. To run the new file enter the following at the command line

    rake db:migrate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create 5 text boxes created on drop down selected index change
I have a drop down list and I want the selected value to put
Ok so I want a drop down select form that when selected on a
How can I get the selected text (not the selected value) from a drop-down
DROP TABLE ( SELECT table_name FROM information_schema.`TABLES` WHERE table_schema = 'myDatabase' AND table_name LIKE
I have a drop down list populated from a database. When i use the
I would like to join data from tables from two databases. One is filed
I am binding a drop down from the database in the follwing way --
How do I access the selected value of a drop down menu from html
I am filling a drop down based on the value selected in the first

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.