我需要在我的 Rails 应用程序中查看 SQL 和存储过程,所以我必须从 schema.rb 更改为 structure.sql。这是我的配置config/application.rb
config.active_record.schema_format = :sql
但是当我在 seed.rb 中为实体创建新记录时
Company.create(
name: 'Google',
subdomain: 'google'
)
发生错误
my_project/db/schema.rb 还不存在
我不知道是什么问题。我是否错过了 cofig 中的某些内容,某个地方仍然需要 schema.rb,或者我错过了一些 rake 任务命令?我刚用
rake db:migrate db:test:prepare
关注此博客https://rietta.com/blog/2013/11/28/rails-and-sql-views-for-a-report/#setting-up-the-sql-view
更新:我正在使用apartment-gem
并且Company
实体是租户。
这是配置apartment.rb
Apartment.configure do |config|
config.excluded_models = %w{ Company CommonField }
config.tenant_names = lambda{ Company.pluck(:subdomain) }
# ==> PostgreSQL only options
config.use_schemas = true
# Apartment can be forced to use raw SQL dumps instead of schema.rb for
# creating new schemas.
# Use this when you are using some extra features in PostgreSQL that can't
# be respresented in
# schema.rb, like materialized views etc. (only applies with use_schemas set
# to true).
# (Note: this option doesn't use db/structure.sql, it creates SQL dump by
# executing pg_dump)
#
# config.use_sql = false
# <== PostgreSQL only options
config.prepend_environment = !Rails.env.production?
end
我尝试更改config.use_schemas
为false
然后启用并设置config.use_sql
为,true
但它仍然无法正常工作。也许它只是为 PostgreSQL 设置的。
那么,对 MySQL 有什么设置吗?