在 Rails 5 中,设置 config.active_record.schema_format = :sql 但仍然在 db:migrate 上创建 schema.rb [英] In Rails 5, setting config.active_record.schema_format = :sql but still getting schema.rb created on db:migrate

查看:61
本文介绍了在 Rails 5 中,设置 config.active_record.schema_format = :sql 但仍然在 db:migrate 上创建 schema.rb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Rails 5 应用程序上工作,我想使用 structure.sql 而不是 schema.rb(我们正在使用具有大量自定义 SQL 调用的 PostGIS...)在 config/initializers/database_options.rb 我有以下内容:

Working on a Rails 5 app, I want to use structure.sql instead of schema.rb (we're using PostGIS with lots of custom SQL calls...). In config/initializers/database_options.rb I have the following:

# use structure.sql, not schema.rb
Rails.application.config.active_record.schema_format = :sql

如果我运行以下:

$ rake db:migrate

它生成db/schema.rb不会 db/structure.sql.

导轨说:

有两种方法可以转储模式.这是设置在config/application.rb 由 config.active_record.schema_format设置,可以是 :sql 或 :ruby.

There are two ways to dump the schema. This is set in config/application.rb by the config.active_record.schema_format setting, which may be either :sql or :ruby.

我在这里错过了什么魔法?

What magic am I missing here?

推荐答案

我认为您应该将 Rails 组件配置放在 Initializers 之前.rails 应用程序按以下顺序初始化.

I think you should put your rails component config before Initializers. The rails application initialize by the following order.

  • config/application.rb
  • 特定于环境的配置文件
  • 初始化程序
  • 后初始化器

你可以把你的配置 config.active_record.schema_format = :sql 放在 config/application.rbconfig/environments/development.rb取决于您使用的环境.

You could put your config config.active_record.schema_format = :sql either in config/application.rb or config/environments/development.rb depends on environment you used.

应该可以.

这篇关于在 Rails 5 中,设置 config.active_record.schema_format = :sql 但仍然在 db:migrate 上创建 schema.rb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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