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

**URL:** <https://www.ruby-forum.com/t/migration-doesnt-load-data-how-to-debug-a-migration/80964>\
**Category:** Rails\
**Created:** [January 2, 2007, 4:53pm UTC](https://www.ruby-forum.com/t/migration-doesnt-load-data-how-to-debug-a-migration/80964 "2007-01-02T16:53:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yitzhakbg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e274bd/32.png) [@yitzhakbg](https://www.ruby-forum.com/u/yitzhakbg)\
**Post date:** [January 2, 2007, 4:53pm UTC](https://www.ruby-forum.com/t/migration-doesnt-load-data-how-to-debug-a-migration/80964/1 "2007-01-02T16:53:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yitzhakbg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e274bd/32.png) [@yitzhakbg](https://www.ruby-forum.com/u/yitzhakbg)\
**Post date:** [January 2, 2007, 6:33pm UTC](https://www.ruby-forum.com/t/migration-doesnt-load-data-how-to-debug-a-migration/80964/2 "2007-01-02T18:33:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yitzhakbg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e274bd/32.png) [@yitzhakbg](https://www.ruby-forum.com/u/yitzhakbg)\
**Post date:** [January 2, 2007, 6:43pm UTC](https://www.ruby-forum.com/t/migration-doesnt-load-data-how-to-debug-a-migration/80964/3 "2007-01-02T18:43:21Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![yitzhakbg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e274bd/32.png) [@yitzhakbg](https://www.ruby-forum.com/u/yitzhakbg)\
**Post date:** [January 3, 2007, 12:31am UTC](https://www.ruby-forum.com/t/migration-doesnt-load-data-how-to-debug-a-migration/80964/4 "2007-01-03T00:31:14Z")

</div>

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](http://www.pragmaticprogrammer.com/titles/rails2) for more book
> 
> information.  
> #—

---

<div class="post-metadata">

**Author:** ![yitzhakbg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e274bd/32.png) [@yitzhakbg](https://www.ruby-forum.com/u/yitzhakbg)\
**Post date:** [January 3, 2007, 1:07am UTC](https://www.ruby-forum.com/t/migration-doesnt-load-data-how-to-debug-a-migration/80964/5 "2007-01-03T01:07:53Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![yitzhakbg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e274bd/32.png) [@yitzhakbg](https://www.ruby-forum.com/u/yitzhakbg)\
**Post date:** [January 4, 2007, 10:56pm UTC](https://www.ruby-forum.com/t/migration-doesnt-load-data-how-to-debug-a-migration/80964/6 "2007-01-04T22:56:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yitzhakbg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e274bd/32.png) [@yitzhakbg](https://www.ruby-forum.com/u/yitzhakbg)\
**Post date:** [September 22, 2014, 9:50am UTC](https://www.ruby-forum.com/t/migration-doesnt-load-data-how-to-debug-a-migration/80964/7 "2014-09-22T09:50:58Z")

</div>

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/](https://quickshiftin.com/blog/2014/09/pragmatic-database-migrations/)

---

<div class="post-metadata">

**Author:** ![yitzhakbg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e274bd/32.png) [@yitzhakbg](https://www.ruby-forum.com/u/yitzhakbg)\
**Post date:** [January 4, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/migration-doesnt-load-data-how-to-debug-a-migration/80964/8 "2007-01-04T22:42:28Z")

</div>

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
