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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:35:02+00:00 2026-06-01T01:35:02+00:00

I’m new to Ruby on Rails, I know things but now I have to

  • 0

I’m new to Ruby on Rails, I know things but now I have to face real projects and do things. I wrote this migration:

  def change
    change_table :societies do |t|
      ## Database authenticatable
        t.string :email,              :null => false, :default => ""
        t.string :encrypted_password, :null => false, :default => ""

        ## Recoverable
        t.string   :reset_password_token
        t.datetime :reset_password_sent_at

        ## Rememberable
        t.datetime :remember_created_at

        ## Trackable
        t.integer  :sign_in_count, :default => 0
        t.datetime :current_sign_in_at
        t.datetime :last_sign_in_at
        t.string   :current_sign_in_ip
        t.string   :last_sign_in_ip

        # Token authenticatable
        t.string :authentication_token

And when I tried to roll it back I get ActiveRecord::IrreversibleMigration
I know where is the mistake and my question is:

Can I just change an applied migration to fix what is wrong and then re-run rake db:migrate?
O do I have to modify the migration with up/down methods, revert the migration and then migrate again?
Or maybe I shoud drop the table with a new migration and re-create it? Which is the best practice?

  • 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-01T01:35:03+00:00Added an answer on June 1, 2026 at 1:35 am

    TL;DR:

    • If the change is not in production yet, you can usually get away with modifying migrations.
    • It’s best practice to keep migration files as clean and limited in number and scope as possible.
    • If the change is already in production or would make life difficult for other devs if you modified it, then add additional migrations to fix the errant previous migrations.
    • You can be a little looser with these guidelines if you’re only adding functionality (the ability to reverse the migration), not changing what the migration would originally have done.

    Full answer:

    If you haven’t pushed anything to the remote/central repository yet, you can do whatever you want with respect to your new changes, since it only affects you. Just change the database and migration files to suit your needs. And in fact, it’s best practice to change the migration files here rather than cluttering the source base with unnecessary migrations.

    If you have pushed to remote but you know for certain that nobody else has pulled from that branch yet (if for example, you are the only user of that branch, or if it’s a small team and you’ve communicated with all members), again you can do whatever you want with the recent changes, including migrations.

    Now, if someone else has pulled, but the change is not live yet, you can still usually do whatever you want if the team is not too large. Just be aware that your changing an already-committed migration file could cause another developer an annoying development environment re-bootstrap if they’re not aware of what you’re doing, so tell them exactly what they need to do to get their dev environment back in sync. So just communicate clearly with the rest of the team in this case.

    Finally, what if the migration has already been pulled into production and run (or if the development team is too large to efficiently coordinate changing migrations with the other devs)? In this case, it’s usually better to write a new migration to reverse the errant one. There are rare cases where a good cowboy programmer can get away with manually editing already-run migrations in production (and where that might even be a good idea), but you have to be very careful in that case because you’re playing with fire (and have an easy revert mechanism if you screw up).

    In any case, if you’re testing thoroughly, it should be very rare for a bad migration to make it all the way to production. It should be unusual for a bad migration to even make it to the central repository (in any branch that more than one dev is working on, that is).

    With that out of the way, let’s say following the above guidelines you’ve already decided it’s okay to change your migrations. Then, to answer your specific questions:

    Can I just change an applied migration to fix what is wrong and then
    re-run rake db:migrate?

    No, once a migration has been run, its id is stored in the database, and it won’t be run again even if the file changes.

    Or do I have to modify the migration with up/down methods, revert the migration and then migrate again?

    You should modify the migration with up/down methods, yes. But as you already said, you can’t revert the migration the official way. Instead you can either re-bootstrap your environment from an empty slate, or you can manually revert the migration using a sql queries (remember to also remove the associated id from the migrations table). Then, re-run the migration.

    Or maybe I shoud drop the table with a new migration and re-create it?

    Don’t do this unless you are forced to (and even then be careful that when running it in production you don’t inadvertently kill data during this process!).

    Finally, it should be noted that if the only change you’re making to the migration file is splitting a “change” into “up/down” methods, and the “up” part is exactly the same after your modification, you can even get away with skirting the above guidelines a bit because it won’t hurt other developers (they can now just rollback something they couldn’t have rolled back before). But err on the side of caution in that case — you don’t want to screw up and accidentally change the up method here even slightly.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.