在 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
发布评论