Error: ActiveRecord: IrreversibleMigration exception, exceptional

Source: Internet
Author: User

Error: ActiveRecord: IrreversibleMigration exception, exceptional
Recently, the field of the database table was modified in rails3.2 and you want to roll back and cancel the operation. However, when you run the rake db: rollback command, an error occurs:

rake aborted!An error has occurred, all later migrations canceled:ActiveRecord::IrreversibleMigration/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/migration/command_recorder.rb:42:in `block in inverse'

My migration content is as follows:

class ChangeVmTempColumns < ActiveRecord::Migration  def change    change_table :vm_temps do |t|      t.change :disksize, :integer, :limit => 8      t.change :mem_total, :integer, :limit => 8    end  endend

I checked the information online. It seems that if the data type conversion in migration is destructive, the rollback cannot be completed. That is to say, when the field type of the database table is modified, the data in the database also changes, so that the changed data cannot be rolled back.

The migration that cannot be undone: Irreversible Migration provides an example: in migration, change_column can be changed from integer to string, but in turn, if the field type is changed from string to integer, we cannot reverse this migration. This is exactly the same as my situation!

On Stackoverflow, ActiveRecord: IrreversibleMigration exception when reverting migration provides a solution: change self. change to self. up and self. down.

The modified migration:

class ChangeVmTempColumns < ActiveRecord::Migration  def self.up    change_table :vm_temps do |t|      t.change :disksize, :integer, :limit => 8      t.change :mem_total, :integer, :limit => 8    end  end  def self.up    change_table :vm_temps do |t|      t.change :disksize, :string      t.change :mem_total, :string    end  endend

Run rake db: rollback. succeeded!

Cause:I originally thought that in Rails, self. the change method directly sets self. up and self. in this example, we can use only one change method for execution and rollback. when the change method is rolled back, it can only be executed by default. Once the above type conversion problem occurs, it cannot be executed normally; however, self. the self. down statement, so that the error of irreversible migration will not occur.


Ralis connects to the remote database and prompts ActiveRecord: ConnectionNotEstablished. The local pl/SQL can access the remote database.

You can connect remotely in the LAN, but cannot connect to the WAN using an Internet ip address?
The IP address and database port need to be mapped on the router.
 
In the ruby script, how does ActiveRecord: Baseestablish_connection connect to two databases?

One connection can only connect to one database
 

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.