如何在不初始化 Rails 的情况下从 schema.rb 创建数据库?

编程入门 行业动态 更新时间:2024-10-13 04:25:03
本文介绍了如何在不初始化 Rails 的情况下从 schema.rb 创建数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从 schema.rb 创建我所有的表

I am trying to create all my tables from schema.rb

我使用了命令:rake db:schema:load"

I used the command: "rake db:schema:load"

然而,这失败了,因为在我的一个初始化程序中,它引用了一个显然不存在的模型/表(因为数据库是空的)

However, this fails because in one of my initializers, it is referencing a model/table that obviously doesn't exist (since the database is empty)

我可以注释掉这些行,然后再次运行 schema:load,但还有其他选择吗?

I could comment out these lines, and then run schema:load again, but is there an alternative?

推荐答案

您可以在初始化程序中添加对表存在的检查.

You can add a check for the table existance in your initializer.

if TheModel.table_exists? // do something with the model end

更多推荐

如何在不初始化 Rails 的情况下从 schema.rb 创建数据库?

本文发布于:2023-10-18 04:27:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1503108.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   情况下   数据库   如何在   rb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!