If you have a model that uses validates_acceptance_of, you have an observer for that model and you try to run the migration responsible for creating the underlying table then the db:migrate task will fail. The actual error you receive will depend upon your database engine – on MySQL it looks something like this:
Mysql::Error: Table 'database_name.table_name' doesn't exist: SHOW FIELDS FROM `table_name`
The culprit is changeset 8208 which allows the attribute used by validates_acceptance_of to actually exist in the database rather than being virtual. When running the migration to create the underlying table, environment.rb causes the model observer to be loaded which in turn loads the model itself. When the model is loaded validates_acceptance_of tries to determine the column names of the (as yet non-existent) table and, yes you guessed it, blows up!
The good news is that changeset 8377 was submitted 4 days ago to fix this problem. To take advantage of it you’ll either have to freeze Rails to the latest revision or you can simply apply the patch if you’re using something like Piston to manage vendor/rails.
18th December Update: Rails 2.0.2 has now been released and includes the fix for this problem.


3 comments
Comment on Rails 2.0: validates_acceptance_of can break migrations by CodeOfficer
December 24th, 2007 @ 10:39 – permalink
Comment on Rails 2.0: validates_acceptance_of can break migrations by Rob
December 29th, 2007 @ 10:45 – permalink
Comment on Rails 2.0: validates_acceptance_of can break migrations by Rob
January 10th, 2008 @ 15:10 – permalink
Leave a reply
You can use Markdown in your comment as well as plain HTML. You can use
<filter:jscode lang="ruby">and</filter:jscode>tags to surround code blocks (supported languages are css, html, javascript and ruby). Your email address will not be published.If your comment doesn’t appear immediately after posting it could have been marked as spam. Don’t worry: we regularly check for and approve incorrectly filtered comments so you shouldn’t have to wait too long for it to be shown.