在主要/副本上下文中创建和迁移设计的用户模型
以下主/复制数据库结构
development:
primary:
<<: *default
database: users_development
username: deploy_root
password: password
host: "localhost"
migrations_paths: db/user_migrate
primary_replica:
<<: *default
database: users_development
username: deploy_readonly
password: password
host: "localhost"
replica: true
已定义为其主要AR定义为:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
connects_to database: { writing: :primary, reading: :primary_replica }
end
但是,当运行以下命令遵循导轨指南所建议的语法
rails generate devise User nick avatar --database users
bin/rails db:migrate
唯一的响应是提示。出现了两个问题:
迁移是创建的,但不是在适当的目录
migrations_paths:db/user_migrate
登录到数据库
user_development =#\ dt
返回,一致地与提示回复没有找到任何关系。换句话说,该表未创建(由
schema.rb
文件确认,文件未更改
指定oprizations_paths
用子目录一个错误的错误数据库连接?
还是Rails应该生成设计用户Nick Avatar -Database用户
Indoke 主代替
用户
?
The following main/replica database structure
development:
primary:
<<: *default
database: users_development
username: deploy_root
password: password
host: "localhost"
migrations_paths: db/user_migrate
primary_replica:
<<: *default
database: users_development
username: deploy_readonly
password: password
host: "localhost"
replica: true
has defined as its main AR defined as:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
connects_to database: { writing: :primary, reading: :primary_replica }
end
However, when The following commands are run following the suggested syntax by the rails guides
rails generate devise User nick avatar --database users
bin/rails db:migrate
the only response is a prompt. Two problems arise:
the migration is created but not in the proper directory
migrations_paths: db/user_migrate
Logging into the database
users_development=# \dt
returns, consistently with the prompt replyDid not find any relations.
In other words the table was not created (which is confirmed by theschema.rb
file being unaltered
is specifying migrations_paths
with a sub directory a mistake for the primary database connection?
Or should rails generate devise User nick avatar --database users
invoke primary
in lieu of users
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假定主要数据库在
迁移
目录中具有其迁移,而不是子目录。运行
Rails生成
使用- 数据库name_of_primary_database
将按照单个数据库应用程序进行。虽然,这个观察者会喜欢以类似方式组织所有迁移,但是
migrations_paths
对于主要数据库不允许。The primary database is assumed to have its migrations in the
migrate
directory, not a sub-directory.Running a
rails generate
with--database name_of_primary_database
will proceed as in single database application.Although, this observer would have enjoyed that all migrations be organised in a similar manner,
migrations_paths
is not allowed for a primary database.