生产数据库不是由rake db:create命令创建的

时间:2010-12-09 18:47:28

标签: ruby-on-rails

我是一个Rails初学者,我在Ubuntu 10.10上使用Rails 3。我的database.yml如下。

development:
  adapter: mysql
  database: project_dev
  username: root
  password: rootpassword
  host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql
  database: project_test
  username: root
  password: rootpassword
  host: localhost

production:
  adapter: mysql
  database: project_production
  username: root
  password: rootpassword
  host: localhost

然后我切换到项目文件夹并运行命令:

rake db:create

但是,只创建了project_dev和project_test数据库。 mysql中不存在project_production数据库。这有什么问题?

请帮助 谢谢

2 个答案:

答案 0 :(得分:62)

这就是预期的方式。要创建生产数据库,请执行以下操作:

RAILS_ENV=production rake db:create

另外,请查看rake db:setup,它会运行您放在db/seeds.rb中的任何内容。

答案 1 :(得分:9)

这是@iain建议的设计。要创建所有数据库,请运行rake db:create:all