Rails rake db:migrate 没有效果

编程入门 行业动态 更新时间:2024-10-12 10:23:45
本文介绍了Rails rake db:migrate 没有效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我今天做了一个新的 Rails 3 应用程序,添加了一个简单的迁移,由于某种原因,当我执行 rake db:migrate 时没有任何反应.它只是暂停几秒钟,然后返回到命令提示符,没有错误或任何东西.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.

推荐答案

迁移无法运行的原因有几个,但最常见的是系统已经认为您定义的所有迁移已经运行了.

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 表中创建一个条目,其中 version 列对应于标识符号.如果您想强制重新运行迁移,您通常可以将其退出并重试.例如,如果您有 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 表中删除相应的记录,然后再次运行 rake db:migrate.

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 rake db:migrate 没有效果

本文发布于:2023-10-18 15:11:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:效果   rake   Rails   migrate   db

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!