如何为现有 RoR 模型生成数据库架构或迁移文件
有没有办法从现有的 RoR 模型生成迁移文件或数据库模式文件?我丢失了原始迁移文件,数据库已被删除,我不想手工编写。
Is there a way to generate a migration file or db schema file from an existing RoR model? I lost my original migration files and the db has been deleted and I don't want to write either by hand.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该有一个在运行迁移后创建的 db/schema.rb 文件。如果您的存储库中没有此文件并且没有数据库备份,那么 ActiveRecord 无法为您做任何事情。
You should have a db/schema.rb file that is created after your migrations have been run. If you don't have this file in your repo and you don't have a db backup then there is nothing ActiveRecord can do for you.
对我来说似乎不可能。 ActiveRecord 模型的属性由数据库架构确定。模型中通常没有任何代码明确说明模型的组成(关联除外)。
It doesn't seem like it would be possible to me. An ActiveRecord model's attributes are determined by the database schema. There is not usually any code within the model that explicitly states what the model consists of (except for associations).