1) Created a migration

def change change_column :price_items, :weight, :float, default: 2 end 

2) learned that change_column irreversible

But you need to get rid of it. It’s not in production, is it just an option to remove it? in a dev base this is a minor change.

  • And what type of column price_items.weight was before the migration? - cheops
  • : float, I just added the default value. - evans
  • Then, if the migration is in production, you could write change_column with the original default value in the down-migration method and execute rake db:rollback or just do another change_column migration. - cheops

1 answer 1

If the migration was not rolled out to production and it is not registered in the schema_migrations table, you can simply delete it and push the changes to the repository.

1) In the develompment environment, it will be sufficient to recreate the database using the following command

 rake db:drop db:create db:migrate db:seed 

Or an even shorter version

 rake db:reset 

2) If you need an exact copy of the production database, take a dump from the sale and deploy it locally with the tools of the database you use.

  • Actually, I thought that I could do another migration of type change_column :price_items, :weight, :float (i.e., just removed the default value), but this option did not work. - evans
  • It would be nice to explicitly set the defalut value, even if it is NULL change_column :price_items, :weight, :float, default: nil - cheops
  • in this case change_column :price_items, :weight, :float == change_column :price_items, :weight, :float, default: nil ? - evans
  • The first case does not change the default value, leaving the old one. If you add a column with add_column , then, yes, the default key gets the value nil , and the column defaults to NULL . - cheops