Error in Basic Rails Migration

I'm using some free time to look through O'Reilly's Ruby on Rails book, and I've hit a presumably simple but confusing stumbling block on migrations. I've googled a bit and looked at the errata but haven't found anything yet. Any help?

(Update: I'm insane. In programming there's this concept of "variables" and "scope" which I apparently overlooked.)

I'm on page 24, building the 'photos' application. I believe I've followed every step of the tutorial to the letter so far. When I run 'rake migrate' I get this:

(in /Users/scott/Projects/Rails/photos)
== CreatePhotos: migrating ====================================================
-- create_table(:photos)
-- photo()
rake aborted!
undefined method 'photo' for #<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x2217a98>

There's practically nothing in the project at this point. I created photos_development and my 001_create_photos.rb looks like this:

class CreatePhotos < ActiveRecord::Migration
  def self.up
    create_table :photos do |t|
      photo.column "filename", :string

  def self.down
    drop_table :photos

I'm on 10.4.8 using Locomotive, which says it has "Standard Rails Sept 2006."

Design Element
Error in Basic Rails Migration
Posted Dec 24, 2006 — 5 comments below


dominik Wagner — Dec 24, 06 2844

This is a simple code error, either you change
photo.column into

or you change
create_table :photos do |t|
create_table :photos do |photo|

cheers and merry xmas,

Scott Stevenson — Dec 24, 06 2846 Scotty the Leopard

So I guess this is what happens when you don't get enough sleep. Sigh. I could remove this post and save some face, but maybe some kindred spirit will find they made the same mistake.

Can I get away with blaming the lack of a compiler?

Daniel Lyons — Dec 24, 06 2851

Don't blame yourself too much. I helped a friend debug his Rails program the other day. He was taking one of the tutorials in the Rails book, and the first item of a particular type he added to the shopping cart was producing a bizarre JavaScript error. It turned out the problem section of code was just this:

@items <<, 1)
@current_item =, 1)

Upon changing that to this, it just worked:

@current_item =, 1)
@items << @current_item

It was one of the more bizarre and hard to track down errors I've ever seen.

Andrei Maxim — Dec 25, 06 2866

Yeah, I've had a couple of weird moments going through the Rails book, but mostly because I forgot to type a semicolon or something like that.

However, creating two almost identical objects (the two calls) is a serious logic error that's usually really hard to track down regardless of the presence of a compiler.

Don Rainwater — Dec 28, 06 2924

What do you think of the O'Reilly book? How does it compare to the PragProg Rails book? I'm about halfway through the second edition of that. It seems like it's covering the bases, but the pace is... brisk. At times, it kinda feels like a written version of that video where they write a blogging app in 10 minutes. Even so, I'm starting to get comfortable with the idea of doing a non-tutorial project with Rails now.


Comments Temporarily Disabled

I had to temporarily disable comments due to spam. I'll re-enable them soon.

Copyright © Scott Stevenson 2004-2015