重命名模型后,我的迁移中断了,我无法再运行 db:create
事情是这样的。我曾经有一个名为 Message 的模型,然后我想重命名它,因此我创建了一个迁移,将该表从 Message 重命名为 Thread。我后来进行了迁移,然后将其添加到该表中。
这工作得很好,它是 db:migrate 的条款,可以继续使用我们现有的数据库。现在我注意到,当我执行 db:create 来创建一个新的数据库时,它失败了,因为rails创建了消息,然后当它向消息添加字段时,我得到一个:
uninitialized constant AddActiveMessageIdToWalls::Message
我认为问题是我还重命名了所有控制器&模型从消息到线程,现在迁移时找不到模型?听起来对吗?
在 Rails 世界中你如何处理这个问题?谢谢
here's what happened. I used to have a Model called Message, I then wanted to rename it so I created a migration that renamed that table from Message to Thread. I had later migrations that then added to that table.
That worked fine, it terms of db:migrate to move forward with our existing databases. Now I noticed that when I do a db:create to create a fresh db it fails, as rails creates Message, then when it goes to add a field to message I get a:
uninitialized constant AddActiveMessageIdToWalls::Message
I think the problem is that I also renamed all the controller & models from message to thread and now the migration can't find the model when migrating? Does that sound right?
How do you deal with this in the rails world? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我喜欢保持我的 db/schema.rb 更新以避免这种情况。因此,当我需要在新环境中创建数据库时,我只需要执行 rake db:create 和 rake db:schema:load 即可。无需迁移。
I like to keep my db/schema.rb updated to avoid this. So when I need to create the db in a new environment, I just need to do the
rake db:create
andrake db:schema:load
. No migration is needed.最简单的解决方案:只需添加一个空 Message <早期迁移中的 ActiveRecord::Base 子类。
easiest solution: just add an empty Message < ActiveRecord::Base subclass in the earlier migration.