Rails的耙分贝:迁移没有影响 [英] Rails rake db:migrate has no effect

查看:134
本文介绍了Rails的耙分贝:迁移没有影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天做了一个新的Rails 3应用程序,添加了一个简单的迁移,以及由于某种原因,没有任何反应,当我耙分贝:迁移。它只是暂停几秒钟,然后返回到命令提示符下,没有任何错误或任何东西。 Schema.rb和数据库逗留空。

I made a new Rails 3 app today, added a simple migration, and for some reason, nothing happens when I do rake db:migrate. It simply pauses a few seconds, then returns to the command prompt, with no errors or anything. Schema.rb and the database stay empty.

任何想法可能是怎么回事?我做了很多应用程序,从来没有过这样的问题。一切都是完全标准的设置了。

Any ideas what could be going on? I've made many apps and never had this problem. Everything is a totally standard setup too.

推荐答案

有几个原因,你的迁移将不会运行,但最常见的是,该系统已经在即时通讯pression,所有的迁移你定义已运行。

There's a few reasons why your migrations won't run, but the most common is that the system is already under the impression that all the migrations you've defined have already run.

每个移民会在 schema_migrations 表格与版本对应的识别号列中的条目。如果您想强制迁移到重新运行你通常可以背出来,并再试。例如,如果你有 20100421175455_create_things.rb ,那么你会使用重新运行它:

Each migration creates an entry in the schema_migrations table with the version column corresponding to the identifier number. If you want to force a migration to re-run you can usually back it out and retry it. For example, if you had 20100421175455_create_things.rb then you would re-run it using:

rake db:migrate:redo VERSION=20100421175455

一个常见的​​情况是,你的移民未能在第一时间运行,它生成异常的实例,但Rails的仍然认为它完成。强行重新运行迁移,删除了 schema_migrations 表中的相应记录,并执行耙分贝:再次迁移。

A common situation is that your migration has failed to run in the first place, that it generated an exception for instance, and yet Rails still considers it complete. To forcibly re-run a migration, delete the corresponding record from the schema_migrations table and run rake db:migrate again.

要在以后避免这种问题的方法之一是用一个自动回退过程定义迁移:

One way to avoid this kind of problem in the future is to define your migrations with an automatic back-out procedure:

class CreateThings < ActiveRecord::Migration
  def self.up
    # ... (migration) ...

  rescue
    # If an exception occurs, back out of this migration, but ignore any
    # exceptions generated there. Do the best you can.
    self.down rescue nil

    # Re-raise this exception for diagnostic purposes.
    raise
  end
end

如果您在迁移一个错误,你会看到控制台上列出的例外。由于迁移已自动回滚,你应该能够再次和运行一遍,直到你得到它的权利。

If you have a mistake in your migration you will see the exception listed on the console. Since the migration has automatically been rolled back you should be able to run it again and again until you get it right.

这篇关于Rails的耙分贝:迁移没有影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆