迁移时:nil:NilClass的未定义方法`to_sym' [英] On Migration: undefined method `to_sym' for nil:NilClass

查看:93
本文介绍了迁移时:nil:NilClass的未定义方法`to_sym'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Rails 3.0.3,并且在迁移过程中意外输入了错字:我创建了一个迁移,该迁移创建了类型为boolen的新列(应该为boolean).我运行了迁移,Rails并没有警告我这是无效的列类型,我可以宣誓在以前的版本中可以做到这一点?

I'm running Rails 3.0.3 and I accidentally made a typo in my migration: I created a migration that creates a new column with a type of boolen (it should have been boolean). I ran the migration and Rails didn't warn me that this was an invalid type of column, which I could have sworn it did in previous versions?

现在,每当我尝试在迁移中添加,删除或修改任何内容时,都会出现以下错误:

Now whenever I try to add, remove, or modify anything in a migration I get the following error:

nil:NilClass的未定义方法"to_sym"

undefined method `to_sym' for nil:NilClass

我什至无法回滚或删除.我保存了较早版本的数据库和文件树,但是这个问题使我发疯,因为这不是我第一次看到这种情况.

I can't even rollback or drop. I have an earlier version of the database and file tree saved, but this problem is driving me crazy because it isn't the first time I've seen this happen.

如何有效地删除列而不会让Rails抱怨(最好不要手工挖掘数据库)?

How can I effectively remove the column without having Rails complain (and preferably without digging into the database by hand)?

推荐答案

这是我在Rails迁移中遇到的一个问题.您拼写了一个错误的名称或错误排列了该字段的名称.这是您可以做的.

This is a problem that I have had with rails migrations. You misspelled or misordered a field with its name. Here is what you can do.

  1. 如果自问题以来仅进行了一次迁移.
  2. rake db:rollback.
  3. 这将使您犯错,并且可以更改问题,我将在以后进行讨论.
  4. 如果不是最后一次迁移,请继续使用rake db:rollback直到您在那里并解决问题为止.
  1. If you have only done one migration since the problem.
  2. rake db:rollback.
  3. That will get you to the mistake and you can change the problem which I will talk about more later.
  4. If it is not the last migration keep going with rake db:rollback until you are there and the problem is fixed.

问题是这样的.注意第一个的顺序和第二个的拼写.这是两个问题,给了我与您现在相同的情况,即to_sym bs.

The problem is something like this. Notice the order on the first one and the spelling on the second one. These are two problems that have giving me the same situation you are in right now which is that to_sym bs.

例如;

 :books, :integer, :name #here I have `integer` before the name
 :books, :name, :integr #here I have the order right but spelling is a problem.

如果您还有其他问题,请告诉我.

Let me know if you have more questions.

如果不能rake db:rollback,然后进行新迁移,则删除出现问题的表,然后重新生成.我以前必须这样做.只要确保您的订单正确无误即可.

If you cannot rake db:rollback then make a new migration, drop the table giving the problem, and regenerate. I've had to do that before. Just make sure you get your order right.

这篇关于迁移时:nil:NilClass的未定义方法`to_sym'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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