小编ahl*_*mer的帖子

什么会导致此迁移挂起?

我正在尝试将旧的1.2.6 Rails应用程序升级到2.3.8,并且我遇到了一些迁移问题.也就是说,如果我在迁移中有类似ModelName.create(:foo =>"bar")的内容,则迁移不会完成.它没有达到无限循环或任何东西.它只是拒绝完成迁移.

这是一些示例代码.

这有效:

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
Run Code Online (Sandbox Code Playgroud)

取消注释Section.create(...)意味着迁移永远不会完成.

这是rake db:migrate --trace的输出:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  CreateNewsArticles: migrating ============================================= …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

3
推荐指数
1
解决办法
1557
查看次数

标签 统计

ruby-on-rails ×1