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.
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