Migration doesn't load data. How to debug a migration?

We’re learning Rails from the 2nd edition of Agile Web development with
Rails under Ubuntu Edgy.
I messed up the Ruby and Gem environment but managed to put the pieces
together. However, there is one outstanding problem:
When running the migrations, they all work, except that the one which
loads data (couldn’t attach, theres a bug on the server) does not load
the data. before the environment got messed up, it did work OK. It’s
funny, because when we run the app. from the browser, data is entered
and stored in the database all right. There is no indication in the log
files that anything is amiss. Simply the data isn’t written into the DB.
Wanted to know if anyone has a hint. Also, how can the migration be
debugged? It is run through Rake?
Thanks

Sometimes when I can’t figure out what is happening with the database, I
put a log on the database and tail it.
in /etc/my.cnf:
log = /var/log/mysqld.log
This will get big fast in production but for development it helps.
Jason

Jason N. wrote:

Sometimes when I can’t figure out what is happening with the database, I
put a log on the database and tail it.
in /etc/my.cnf:
log = /var/log/mysqld.log
This will get big fast in production but for development it helps.
Jason

I looked there (I also tried with Sqlite - can’t find it’s log file),
but saw nothing relevant. That’s why I wanted to try using the debugger.
It’s weird. It worked before I screwed up the Ruby environment. After i
restored the Ruby environment, everything works OK, including my other
migrations 9which don’t load data. Loading data also works OK, through
the web interface of the application. Only loading of data through the
migration doesn’t work.
here’s the migration (there’s a bug on this forum when trying to attach
a file):
#—

Excerpted from “Agile Web D. with Rails, 2nd Ed.”

We make no guarantees that this code is fit for any purpose.

Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book

information.
#—

class AddTestData < ActiveRecord::Migration
def self.up

Product.create(:title => 'Pragmatic Project Automation',
:description =>
%{<p>
   <em>Pragmatic Project Automation</em> shows you how to improve 

the
consistency and repeatability of your project’s procedures using
automation to reduce risk and errors.



Simply put, we’re going to put this thing called a computer to
work
for you doing the mundane (but important) project stuff. That
means
you’ll have more time and energy to do the really
exciting—and difficult—stuff, like writing quality code.

},
:image_url => ‘/images/auto.jpg’,
:price => 29.95)

Product.create(:title => 'Pragmatic Version Control',
  :description =>
  %{<p>
     This book is a recipe-based approach to using Subversion that 

will
get you up and running quickly—and correctly. All projects
need
version control: it’s a foundational piece of any project’s
infrastructure. Yet half of all project teams in the U.S. don’t
use
any version control at all. Many others don’t use it well, and
end
up experiencing time-consuming problems.

},
:image_url => ‘/images/svn.jpg’,
:price => 28.50)

# . . .


Product.create(:title => 'Pragmatic Unit Testing (C#)',
:description =>
%{<p>
    Pragmatic programmers use feedback to drive their development 

and
personal processes. The most valuable feedback you can get while
coding comes from unit testing.



Without good tests in place, coding can become a frustrating
game of
“whack-a-mole.” That’s the carnival game where the player
strikes at a
mechanical mole; it retreats and another mole pops up on the
opposite side
of the field. The moles pop up and down so fast that you end up
flailing
your mallet helplessly as the moles continue to pop up where you
least
expect them.

},
:image_url => ‘/images/utc.jpg’,
:price => 27.75)

end

def self.down
Product.delete_all
end
end

I’m having the same exact problem. I downloaded the same code and
migration won’t work. I dropped all my data and raked it again and still
nothing.

Only loading of data through the
migration doesn’t work.
here’s the migration (there’s a bug on this forum when trying to attach
a file):
#—

Excerpted from “Agile Web D. with Rails, 2nd Ed.”

We make no guarantees that this code is fit for any purpose.

Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book

information.
#—

jman wrote:

I’m having the same exact problem. I downloaded the same code and
migration won’t work. I dropped all my data and raked it again and still
nothing.

Only loading of data through the
migration doesn’t work.
here’s the migration (there’s a bug on this forum when trying to attach
a file):
#—

Excerpted from “Agile Web D. with Rails, 2nd Ed.”

We make no guarantees that this code is fit for any purpose.

Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book

information.
#—

Nice to know that I’m in good company. Know what? I’m going to post this
on the one of the relevant Pragmatic Programmers forums/wikis.

Drew O. wrote:

Yitzhak Bar G. wrote:

Nice to know that I’m in good company. Know what? I’m going to post this
on the one of the relevant Pragmatic Programmers forums/wikis.

I was having the same problems as well and was able to fix them by
updating rails to the absolute newest version, which is the release
candidate of Rails 1.2.0. You need this version of Rails in order to
follow the examples in the book.

-Drew

Thanks Drew,
In my case, it didn’t solve the problem. I’ll check again to make sure
it was the latest version. In any case, I was wondering how one goes
about debugging a migration.
Yitzhak

Checkout this article about enhancing the migrations system to work well
with multiple lines of development in version control!

https://quickshiftin.com/blog/2014/09/pragmatic-database-migrations/

Yitzhak Bar G. wrote:

Nice to know that I’m in good company. Know what? I’m going to post this
on the one of the relevant Pragmatic Programmers forums/wikis.

I was having the same problems as well and was able to fix them by
updating rails to the absolute newest version, which is the release
candidate of Rails 1.2.0. You need this version of Rails in order to
follow the examples in the book.

-Drew