如何在不初始化 Rails 的情况下从 schema.rb 创建数据库? [英] How to create database from schema.rb without initializing Rails?

查看:40
本文介绍了如何在不初始化 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 创建数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆