我可以将迁移文件从一个 ror 项目复制到另一个项目吗?
我只是尝试将这些迁移文件从以前的项目复制到当前的项目,这样我就不会再次生成类似的数据库结构。 但在我尝试“rake db:migrate”并编辑一些控制器后,它显示即使迁移成功,它也找不到这些模型。 所以我回滚并尝试重新创建这些文件并进行复制粘贴工作人员,它终于起作用了。
谁能向我解释为什么? 谢谢。
I just tried to cp those migration files from my former projects to my present project so that i won't generate the similar db structure again.
but after i tried "rake db:migrate" and edit some controllers it shows that it can not find those models even if it was migrated successfully.
so i rolled back and tried to recreate those files and did copy-paste staff and it finally works.
can anyone explain why to me?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您手动检查并组合迁移
*.rb
文件,而不是仅仅复制它们。仅仅复制/粘贴所有内容是一个坏主意。
Instead of just copying over the migration
*.rb
files, I would suggest that you go through them manually and combine them.Just copy/pasting everything is a bad idea.
迁移仅创建表,而不创建模型。要创建模型,您还需要从
app/models/
目录复制文件。复制迁移应该可以工作,它们只是带有时间戳的文件(时间戳是否来自创建项目之前并不重要,它必须是唯一的),映射到create table
/alter table
/... 数据库的命令。Migrations only create tables, not models. To create models, you need to copy files from
app/models/
directory too. And copying migrations should work, they're just files with timestamp (it doesn't matter it timestamp is from before project was created, it just has to be unique) which maps tocreate table
/alter table
/... commands of your database.