在 Rails 5 中,设置 config.active

编程入门 行业动态 更新时间:2024-10-13 22:22:12
本文介绍了在 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.rb 或 config/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

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

发布评论

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

>www.elefans.com

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