SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy rake aborted! migration failing

    so im following Lenz's book and im trying to add a table to the database. I guess whats happening is that migrating will merge my new table to the existing one for the 'Story' table, however i guess the error below. Im very new, please help!


    C:\InstantRails\rails_apps\shovell>rake db:migrate
    (in C:/InstantRails/rails_apps/shovell)
    == CreateStories: migrating ===================================================
    -- create_table( :stories)
    rake aborted!
    Mysql::Error: #42S01Table 'stories' already exists: CREATE TABLE stories (`id` i
    nt(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255) DEFAULT NULL
    , `link` varchar(255) DEFAULT NULL) ENGINE=InnoDB

    (See full trace by running task with --trace)

  2. #2
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    trace

    when i run the trace i get this (what does it mean!?)


    C:\InstantRails\rails_apps\shovell>rake db:migrate --trace
    (in C:/InstantRails/rails_apps/shovell)
    ** Invoke db:migrate (first_time)
    ** Invoke environment (first_time)
    ** Execute environment
    ** Execute db:migrate
    == CreateStories: migrating ===================================================
    -- create_table( :stories)
    rake aborted!
    Mysql::Error: #42S01Table 'stories' already exists: CREATE TABLE stories (`id` i
    nt(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255) DEFAULT NULL
    , `link` varchar(255) DEFAULT NULL) ENGINE=InnoDB
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/connection_adapters/abstract_adapter.rb:128:in `log'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/connection_adapters/mysql_adapter.rb:243:in `execute'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/connection_adapters/abstract/schema_statements.rb:104:in `create_table'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/connection_adapters/mysql_adapter.rb:353:in `create_table'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/migration.rb:275:in `method_missing'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/migration.rb:259:in `say_with_time'
    C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/migration.rb:259:in `say_with_time'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/migration.rb:273:in `method_missing'
    ./db/migrate//001_create_stories.rb:3:in `real_up'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/migration.rb:212:in `migrate'
    C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/migration.rb:212:in `migrate'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/migration.rb:335:in `migrate'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/migration.rb:330:in `migrate'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/migration.rb:297:in `up'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_recor
    d/migration.rb:288:in `migrate'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/databases.rake
    :4
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execu
    te'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execu
    te'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invok
    e'
    C:/InstantRails/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invok
    e'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_
    level'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_
    level'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `stan
    dard_exception_handling'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in `top_
    level'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1711:in `run'

    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `stan
    dard_exception_handling'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run'

    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/bin/rake:7
    C:/InstantRails/ruby/bin/rake.bat:25

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Kaysville, UT
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are trying to create the same table twice, or you are trying to create a table that already exists outside of the migration process.

    First, look through your migration scripts. Are any two (or more) of them trying to create the same table? If so, remove all but the first one. Subsequent ones should alter the table, not create it again.

    If that isn't the case, you've probably previously created the table. It won't merge them if one with the same name already exists. You can either drop the old table, rename your new table, or use a different database.
    Spencer Uresk
    Rails App Hosting
    Cheap Hosting - Directory of hosting plans under $10/month!
    My blog: Tech and Java Articles

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The MySQL Administrator works very well under Windows (The Linux version is a little flaky). It can be down loaded for free from here:

    http://dev.mysql.com/downloads/gui-tools/5.0.html

    It is bundled together with some other useful looks such as a query browser.

    As you appear to be running on Windows, I recommend you use the MySQL Administrator to inspect the tables you have in your database. This will let you determine whether the table actually exist (which I expect it does), examine it, and delete it if you wish (doing this will allow you to then successfully run the migration I expect).

    Please note - also do as suresk suggests. I hope to point you in the direction of a tool that will help you fix the immediate problem. suresk advise will help you determine what caused the problem and avoid doing it again, in my opinion.

  5. #5
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the replies! i tried what suresk suggested. in my db/migrate folder I have two scripts that are creating tables. in the create_stories.rb file I have commented out the stories script (sorry i was mistaken, they are not supposed to merge).

    ======create_stories.rb=======
    class CreateStories < ActiveRecord::Migration
    def self.up
    # create_table :stories do |t|
    # t.column :name, :string
    # t.column :link, :string
    end
    end

    def self.down
    drop_table :stories
    end
    end

    =====create_votes.rb=======
    class CreateVotes < ActiveRecord::Migration
    def self.up
    create_table :votes do |t|
    t.column :story_id, :integer
    t.column :created_at, :datetime
    end
    end

    def self.down
    drop_table :votes
    end
    end

    I get a different error now! I'll make sure to try the MySQL Administrator, but i was hoping to get this working for the future because i always have problems when I migrate... thanks for all the help!

    C:\InstantRails\rails_apps\shovell>rake db:migrate
    (in C:/InstantRails/rails_apps/shovell)
    rake aborted!
    ./db/migrate//001_create_stories.rb:12: parse error, unexpected kEND, expecting
    $

    (See full trace by running task with --trace)

  6. #6
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unexpected kEND in create_stories.

    What do you think that means?

    Perhaps one of your "end"s wasn't expected by the interpreter? Why might that happen?
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Kaysville, UT
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, first off, commenting out the story migration may help, but I don't know that it is the right way to approach the problem. From what you've shown here, it looks as though your migrations are setup right, but for some reason a stories table already exists. So either delete it in mysql (check to make sure nothing important is using it first!) or use another database. Commenting out the migrations will make it tricky when you go to deploy to production or to a different machine.

    Second, here is why your commented-out migration is failing:

    def self.up
    # create_table :stories do |t|
    # t.column :name, :string
    # t.column :link, :string
    end
    end

    create_table is a block, meaning it has an 'end' statement. You forgot to comment it out. If you were going to comment that part out, you'd do:

    def self.up
    # create_table :stories do |t|
    # t.column :name, :string
    # t.column :link, :string
    #end
    end

    Hope that helps.
    Spencer Uresk
    Rails App Hosting
    Cheap Hosting - Directory of hosting plans under $10/month!
    My blog: Tech and Java Articles

  8. #8
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ohhh!! im such a newbie...i had one extra 'end' in my create_stories file. i removed it and it created the votes table perfectly! thanks for trying to help! :P


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
  •