生成用于丢弃迁移的轨道模型
我有一个模型客户,是我使用以下代码生成的
rails g 模型客户名称:字符串
一段时间后,我决定将模型重命名为 customer_type,为了完成此任务,我们编写了另一个迁移
rails g 迁移RenameCutomerToCustomerType
一切都很顺利,直到我需要添加名为 customer 的模型。当我发出以下命令时,我开始收到“另一个迁移已命名为 create_customer”
rails g 模型客户
我认为这种情况在基于 CRUD 的项目中很常见,请建议如何解决这个问题?这是 Rails 的限制吗?
I had a model customer, which I have generated using the following
rails g model Customer name:string
After some time, I decided to rename the model to customer_type, to accomplish this we wrote an another migration
rails g migration RenameCutomerToCustomerType
everything was smooth until I had the requirement to add the model named customer. When I issued the following command, I've started getting "Another migration is already named create_customer"
rails g model Customer
I think this kind of scenario is very common in CRUD based project, please suggest on how to over come this? Is this a limitation with rails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需重命名旧的迁移文件名和类名即可。两者都不影响什么。
顺便说一句:这种情况非常罕见,所以我认为框架不需要采取任何特定操作
Just rename old migration filename and classname. Both don't affect anything.
btw: This scenario is quite rare so I don't think that there is any need in specific actions from framework
Rails destroy model MODELNAME,将删除该模型。
rails destroy model MODELNAME, will remove the model.