Odd migration issue with Paperclip - presence of has_attached_file prevents migration?

12 views
Skip to first unread message

H. Wade Minter

unread,
Aug 19, 2008, 6:24:32 PM8/19/08
to Paperclip Plugin
I have a branch of my application where I am developing a new
feature. The branch introduces a migration that adds a new table, and
a model that uses Paperclip.

As part of the testing, I refreshed the database on that branch from
production (where it didn't have the new table), and attempted to run
the migrations again to add that table back. However, I got:

###
minter:(git)cwx[wallofshame]/$ rake db:migrate
(in /Users/minter/git/cwx)
rake aborted!
Mysql::Error: Table 'cwx.audience_volunteers' doesn't exist: SHOW
FIELDS FROM `audience_volunteers`

(See full trace by running task with --trace)
###

Looking at it with --trace, I saw it was complaining about the
has_attached_file line in my model:

###
class AudienceVolunteer < ActiveRecord::Base
has_attached_file :picture, :styles => { :large =>
"1024x768", :medium => "640x480", :default => "400x300", :small =>
"200x150", :thumb => "100x75" }
###

If I comment out has_attached_file and a validates_attachment_presence
line in the model, the migration will run. With those lines active,
though, the migration will not.

Is that expected behavior?

--Wade

Jonathan Yurek

unread,
Aug 20, 2008, 9:08:17 AM8/20/08
to papercli...@googlegroups.com
Hello,

Someone else mentioned something about a migration issue. They thought
it was related to auto_migrations, but that's as far as that went.
What plugins are you using alongside paperclip? Perhaps there is a
conflict somewhere. There's nothing inherent in paperclip that will
cause migrations to fail (that I know of anyway).

--
Jonathan Yurek, Founder and CTO
thoughtbot, inc.
organic brains. digital solutions.

617.482.1300 x114
http://www.thoughtbot.com/

H. Wade Minter

unread,
Aug 20, 2008, 11:39:45 AM8/20/08
to Paperclip Plugin
I have several other plugins:

minter:(git)cwx[wallofshame]/$ ls vendor/plugins/
12_hour_time exception_notification query_reviewer
acts_as_list facebox_render rails-footnotes
attachment_fu fckeditor restful_authentication
calendar_date_select jrails will_paginate
calendar_helper paperclip

However, the problem was resolved when I commented out the paperclip
lines in the model, so it seems like that's where it may be. It seems
like it's loading the model and attempting to read the database table
during the migrations, and of course the table doesn't exist yet.

--Wade

Jonathan Yurek

unread,
Aug 21, 2008, 10:28:08 AM8/21/08
to papercli...@googlegroups.com
Ahh, yes. That's what it is. There's a check now when Paperclip is
loaded to see that the columns are in place. I hadn't come across this
because we consider it best practice never to load models in
migrations in order to make sure they can always be run (a point we
disagree with Rails Core on, apparently). Also I figured that failing
early for missing columns is better than failing late, but I suppose
in this case it isn't.

Anyway, I can move the check for the columns to
Paperclip::Attachment#assign, so it won't be fired until it's actually
used. That way there's still an error, but it won't mess up migrations.

H. Wade Minter

unread,
Aug 21, 2008, 10:58:40 AM8/21/08
to Paperclip Plugin
That sounds like it'd work great!
Reply all
Reply to author
Forward
0 new messages