I have what I think is a pretty simple migration. For some reason I get an IrreversibleMigration
error when I try to db:rollback
or db:migrate:redo
.
The migration runs smoothly, but I'd rather keep it reversible. I can't figure out why it's not as written. Any ideas?
Here's the migration:
class AddWhyHypAndWhyHypeToStatements < ActiveRecord::Migration def change change_table :statements do |t| t.rename :description, :why_hypocritical t.text :why_hypothetical end end end
If it matters, "description" column is a text column. I'm using Rails 3.1/Ruby 1.9.2/PostgreSQL. Thanks for any help.
The migration that cannot be undone: Irreversible Migration.
Introduced in Rails 4.0, reversible makes it possible to tell a migration using change (instead of up and down ) how to reverse migrations that Active Record doesn't know how to reverse by default, so that you can specify code to be executed whether migrating forward or rolling back, even inside a migration implemented ...
You can change the migration file name, but you have to perform a few steps: rake db:rollback to the point that queries table is rolled back. Now change the name of migration file, also the contents. Change the name of any Model that may use the table.
Reversible Migrations Rails allows us to rollback changes to the database with the following command. rails db:rollback. This command reverts the last migration that was run on the database. If the migration added a column event_type then the rollback will remove that column.
Looks like Rails has troubles reverting change_table
method. Try doing it that way instead:
class AddWhyHypAndWhyHypeToStatements < ActiveRecord::Migration def change rename_column :statements, :description, :why_hypocritical add_column :statements, :why_hypothetical, :text end end
You can see the list of commands that can be inverted in the docs or in Rails Guides.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With