5

我已經搜索瞭如何在rails的生產環境中創建數據庫並獲得了2個答案。現在我對這些答案感到困惑。在rails的生產環境中創建數據庫

RAILS_ENV=production rake db:create db:schema:load 
RAILS_ENV=production rake db:create 

這兩者有什麼區別?這個模式意味着什麼?

爲什麼我們需要db:schema:load

在此先感謝。

+0

[rake db:migrate db:reset and db:schema:load]之間的差異可能重複(http://stackoverflow.com/questions/10301794/difference-between-rake-dbmigrate-dbreset-and-dbschemaload) – mlt 2016-06-02 20:42:10

回答

6

RAILS_ENV=production rake db:create將在數據庫爲production環境,

RAILS_ENV=production rake db:schema:load將創建根據schema.rbproduction環境中的數據庫中的表和列。

task :load => [:environment, :load_config] do 
    ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:ruby, ENV['SCHEMA']) 
end 

task :create => [:load_config] do 
    ActiveRecord::Tasks::DatabaseTasks.create_current 
end 

查看this file瞭解有關該主題的完整信息。