small medium large xlarge

Generic-user-small
20 Aug 2008, 04:16
Mark Bush (8 posts)

This is a re-post after my formatting disaster!

Hey everyone, I am having a doozie here, can’t figure out what I am doing wrong!

After running the migration, this is all I get:

== 20080820011922 AddTestData: migrating ====================================== == 20080820011922 AddTestData: migrated (0.0150s) =============================

I am running the most up-to-date rails (2.1.0). I am trying to run the migration from the code that will populate my database with information to work with . . . but its not working! My database remains empty! I am creating the migration as it states in the book, and filling it in with the code from this website. Here is the code:

class AddTestData < ActiveRecord::Migration def self.up Product.delete_all

Product.create(:title => 'Pragmatic Project Automation',
:description => 
,
: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.
  </p>},
: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.
  </p>
  <p>
    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.
  </p>},
:image_url => '/images/utc.jpg',
:price => 27.75)

end

def self.down Product.delete_all end end

After running this my database remains empty(using the default, sqlite3). And I am able to enter this data manually in the scaffold . . . it just does not populate from the migration! So i tried to troubleshoot, I ran script/console and typed(and recieved):

a = Product.new => #<Product id: nil, title: nil, description: nil, image_url: nil, created_at: nil, updated_at: nil, price: #<BigDecimal:2016948,’0.0’,4(8)» a.title = ‘Pragmatic Project Automation’ => “Pragmatic Project Automation” a.description = %{<p>Pragmatic Project Automation shows you how to improve the consistency and repeatability of your project’s procedures using automation to reduce risk and errors.</p><p>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.</p>} => “<p>Pragmatic Project Automation shows you how to improve the consistency and repeatability of your project’s procedures using automation to reduce risk and errors.</p><p>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.</p>” a.image_url = ‘/images/auto.jpg’ => “/images/auto.jpg” a.price = 29.95 => 29.95 a.save => false

So as you can see . . . I can’t even save from the command line! Anyone have an idea what I am doing wrong?

Generic-user-small
20 Aug 2008, 04:18
Mark Bush (8 posts)

This formatting is all messed up too! if anyone can include formatting tips for posting, appreciations a praise!

Thanks

Samr_small_pragsmall
20 Aug 2008, 12:03
Sam Ruby (634 posts)

re: formatting tips

Immediately below the text area where you enter your comments, there is a link to Formatting instructions. Wrap the code you want displayed in <pre> and <code> tags.

re: migration

I don’t see anything obviously wrong, but you could try downloading a version that is known to work from “here”:http://media.pragprog.com/titles/rails3/code/depot_r/db/migrate/20080601000003_add_test_data.rb

Generic-user-small
20 Aug 2008, 15:50
Mark Bush (8 posts)

Hey Sam!

The code I used is copied from that file. Since this file is really just a way to populate the database with test data, I went ahead and made some of my own . . . but I sure would like to know what’s going wrong.

Samr_small_pragsmall
21 Aug 2008, 00:03
Sam Ruby (634 posts)

I missed on my first reading that you can NOT save from within script/console (somehow, I initially read that backwards).

Try it again from within script/console, and then see what a.errors returns.

You must be logged in to comment