简体   繁体   English

试图创建一个脚手架,但迁移已存在于Rails中

[英]Tried to create a scaffold but migration already exists in Rails

I tried to create a new scaffold called Message and got this error message: 我试图创建一个名为Message的新支架,并收到以下错误消息:

Another migration is already named create_messages

What can I do aside from changing the name of my model/controller/views (which I don't want to do)? 除了更改模型/控制器/视图的名称(我不想这样做)之外,我还能做什么?

The reason this is occurring is I had a previous scaffold called Message that I changed to a different name (ran a migration to do this along with a search and replace for all filenames and variable/class names). 发生这种情况的原因是,我以前有一个名为Message支架,我将其更改为其他名称(进行了迁移,以进行搜索以及替换所有文件名和变量/类名)。 I understand why I get this error message, just want to know how to move forward. 我了解为什么收到此错误消息,只是想知道如何前进。

Quick fix is to rename old migration ( create_messages ) and try to generate scaffold again. 快速解决方案是重命名旧迁移( create_messages ),然后尝试再次生成支架。

But recommendation is to have single create_messages migration so that it can be safely deleted by destroy scaffold command. 但是建议您进行一次create_messages迁移,以便可以通过destroy scaffold命令安全地删除它。

Update: 更新:

If already have Message model then no point in generating Message Scaffold, since scaffold does the same thing again with additional works like generating controller, routes etc. 如果已经具有Message模型,那么生成Message Scaffold毫无意义,因为scaffold还会通过生成控制器,路由等其他工作再次执行同一操作。

If you already have a migration called create_messages you probably already have a Message model(Which means you can't have another named the same). 如果您已经有一个名为create_messages的迁移,那么您可能已经有一个Message模型(这意味着您不能再有一个同名的模型)。 If you have now decided you want to have a scaffold on the model to get the extra controller and view code use the following where name is the name of the column. 如果您现在决定要在模型上安装一个脚手架以获得额外的控制器并查看代码,请使用以下命令,其中name是列的名称。

rails g scaffold Message name --skip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM