Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Merge pull request #7050 from kytrinyx/documentation-reset-column-info

Expand the caveat about models in migrations in the rails guide.
  • Loading branch information...
commit cd98c25ebedc27fe892468bb87ea260fb070f5eb 2 parents e5e174a + a1d2f69
@vijaydev vijaydev authored
Showing with 21 additions and 0 deletions.
  1. +21 −0 guides/source/
21 guides/source/
@@ -889,6 +889,27 @@ class AddFuzzToProduct < ActiveRecord::Migration
+There are other ways in which the above example could have gone badly.
+For example, imagine that Alice creates a migration that selectively
+updates the +description+ field on certain products. She runs the
+migration, commits the code, and then begins working on the next feature,
+which is to add a new column +fuzz+ to the products table.
+She creates two migrations for this new feature, one which adds the new
+column, and a second which selectively updates the +fuzz+ column based on
+other product attributes.
+These migrations run just fine, but when Bob comes back from his vacation
+and calls `rake db:migrate` to run all the outstanding migrations, he gets a
+subtle bug: The descriptions have defaults, and the +fuzz+ column is present,
+but +fuzz+ is nil on all products.
+The solution is again to use +Product.reset_column_information+ before
+referencing the Product model in a migration, ensuring the Active Record's
+knowledge of the table structure is current before manipulating data in those
Schema Dumping and You
Please sign in to comment.
Something went wrong with that request. Please try again.