In Rails 5, setting config.active_record.schema_format = :sql but still getting schema.rb created on db:migrate

浪尽此生 提交于 2020-05-15 04:33:46

问题


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

If I run the following:

$ rake db:migrate

it generates db/schema.rb, not db/structure.sql.

The rails guides say:

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?


回答1:


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

  • config/application.rb
  • Environment-specific configuration files
  • Initializers
  • After-initializers

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.

That should work.




回答2:


In your initializer do:

Rails.application.configure do
  config.active_record.schema_format = :sql
end


来源:https://stackoverflow.com/questions/41369035/in-rails-5-setting-config-active-record-schema-format-sql-but-still-getting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!