简体   繁体   English

rake db:create 可以在多个数据库中创建表吗?

[英]Can rake db:create create tables in multiple databases?

Can I create tables in two databases using db:create ?我可以使用db:create在两个数据库中创建表吗? For example, can I have entries in database.yml for one_development and two_development and have both get created by rake db:create ?例如,我可以在database.yml中有one_developmenttwo_development的条目,并且都由rake db:create吗? I know rake db:create:all works -- I am just wondering if there is a way to segment what is created depending on the RAILS_ENV?我知道 rake db:create:all 有效——我只是想知道是否有办法根据 RAILS_ENV 对创建的内容进行分段?

For one_development you can execute this command:对于one_development ,您可以执行以下命令:

RAILS_ENV=one_development rake db:create

For two_development you can execute this command:对于two_development ,您可以执行以下命令:

RAILS_ENV=two_development rake db:create

Redefine the rake task or create a new one, which runs rake db:create for two environments that you need.重新定义 rake 任务或创建一个新任务,该任务为您需要的两个环境运行rake db:create

It appears to do all the datasets automatically.它似乎自动完成所有数据集。 See the source:查看源代码:

http://dev.rubyonrails.org/changeset/6849 http://dev.rubyonrails.org/changeset/6849

It does not appear to uses RAILS_ENV like drop, etc.它似乎没有像 drop 等那样使用 RAILS_ENV。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM