views:

17

answers:

2

I'm trying to upgrade an old 1.2.6 Rails application to 2.3.8, and I'm running into a bit of a snag with migrations. Namely, if I have something like ModelName.create(:foo => "bar") in the migration, the migration doesn't complete. It doesn't hit an infinite loop or anything. It just refuses to complete that migration.

Here's some sample code.

This works:

class CreateNewsArticles < ActiveRecord::Migration
  def self.up
    create_table :news_articles, :force => true do |t|
      t.string  "name"
      t.string  "image"
      t.text    "body"
      t.boolean "featured", :default => "0"
      t.integer "position"
      t.timestamps
    end
    # Section.create(:name => 'News Articles', :controller => 'news_articles', :description => 'Add, edit, and delete news articles.')
  end

  def self.down
    drop_table :news_articles
    Section.find_by_name('News Articles').destroy
  end
end

Uncommenting the Section.create(...) means the migration never completes.

Here's the output from rake db:migrate --trace:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  CreateNewsArticles: migrating =============================================
-- create_table(:news_articles, {:force=>true})
   -> 0.0531s

And after commenting out the Section.create

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  CreateNewsArticles: migrating =============================================
-- create_table(:news_articles, {:force=>true})
   -> 0.0479s
==  CreateNewsArticles: migrated (0.0481s) ====================================

** Invoke db:schema:dump (first_time)
** Invoke environment 
** Execute db:schema:dump

I've tried this on another computer, and it works. Same version of rake, same version of ruby, and rails is frozen.

rake --VERSION: rake, version 0.8.7, ruby -v: ruby 1.8.6 (2010-02-05 patchlevel 399) [i686-darwin10.3.0], rails -v: Rails 2.3.8

Anyone have any ideas?

A: 

Apparently using ruby 1.8.6-p399 was the culprit. Switching to 1.8.6-p369 solved it.

ahlatimer
A: 

You might also try defining a bar-bones section model in the migration.

thomasfedb
Is the issue that the migration couldn't find the Section model? It seems odd that it would just exit without throwing an error.
ahlatimer
I'm not sure, its just something I try when migrations go weird. Especially helpful if the model has information about an older schema.
thomasfedb