SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation RoR 2: Chapter 6 pg 183 - rake test:units

    When I attempt to tun the test, I do not get expected results. Here is what I get:

    Code Ruby:
    C:\InstantRails-2.0-win\rails_apps\shovell>rake test:units
    (in C:/InstantRails-2.0-win/rails_apps/shovell)
    You have 1 pending migrations:
         1 CreateStories
    Run `rake db:migrate` to update your database then try again.

    That being the case, I attempt to run rake db:migrate, but I get this error:

    Code Ruby:
    C:\InstantRails-2.0-win\rails_apps\shovell>rake db:migrate
    (in C:/InstantRails-2.0-win/rails_apps/shovell)
    == 1 CreateStories: migrating =================================================
    -- create_table(:stories)
    rake aborted!
    SQLite3::SQLException: table stories already exists: CREATE TABLE stories ("id"
    INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255) DEFAULT NULL, "l
    ink" varchar(255) DEFAULT NULL, "created_at" datetime DEFAULT NULL, "updated_at"
     datetime DEFAULT NULL)
     
    (See full trace by running task with --trace)


    Any ideas on why I have a pending migration that I can not remove or what I need to do?

    Thanks!

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,226
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)
    Hi hwcasey12, welcome to the forums.

    How many files do you have in the shovell\db\migrate folder? In mine I have only one named [YYYYMMDDhhmmss]_create_stories.rb and it looks like
    Code Ruby:
    class CreateStories < ActiveRecord::Migration
      def self.up
        create_table :stories, :force => true do |t|
          t.string :name
          t.string :link
     
          t.timestamps
        end
      end
     
      def self.down
        drop_table :stories
      end
    end

  3. #3
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have one file named "001_create_stories.rb"

    Mine was close to yours, but I was miss the ", :force => true"

    Code Ruby:
    class CreateStories < ActiveRecord::Migration
      def self.up
        create_table :stories, :force => true do |t|
          t.string :name
          t.string :link
     
          t.timestamps
        end
      end
     
      def self.down
        drop_table :stories
      end
    end

    I made the adjustment and ran /shovell>rake db:migrate.

    IT DID IT SUCCESSFULLY!

    Code Ruby:
    C:\InstantRails-2.0-win\rails_apps\shovell>rake db:migrate
    (in C:/InstantRails-2.0-win/rails_apps/shovell)
    == 1 CreateStories: migrating =================================================
    -- create_table(:stories, {:force=>true})
       -> 0.1720s
    == 1 CreateStories: migrated (0.1720s) ========================================

    Thank you for your help. What step did I miss in working through this book that caused me to be missing that information from that file?

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,226
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)
    The details in my book start on page 127 under "Creating the stories Table" with the code modification excerpt at the top of page 129, and then it explains how :force => true works.

  5. #5
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks that helped me too!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •