Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在rails迁移中加载数据?_Ruby On Rails_Migration - Fatal编程技术网

Ruby on rails 在rails迁移中加载数据?

Ruby on rails 在rails迁移中加载数据?,ruby-on-rails,migration,Ruby On Rails,Migration,我有一个大型数据库,我需要在最初运行应用程序之前填充数据。最好在外部rake任务或内部迁移中执行此操作 真诚地, Tyler文件db/seeds.rb就是为此而设计的。它应该在创建Rails项目时自动生成。它的顶部有一条注释,解释了如何使用它: # This file should contain all the record creation needed to seed the database with its default values. # The data can then be

我有一个大型数据库,我需要在最初运行应用程序之前填充数据。最好在外部rake任务或内部迁移中执行此操作

真诚地,
Tyler

文件
db/seeds.rb
就是为此而设计的。它应该在创建Rails项目时自动生成。它的顶部有一条注释,解释了如何使用它:

# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#   
#   cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
#   Major.create(:name => 'Daley', :city => cities.first)

填充后,使用
rake db:seed
将种子数据填充到数据库中。

我认为这个文件只存在于Rails 3之后。但是,如果您想更早地使用它,只制作文件并自己添加rake任务应该不会有问题<代码>[~/code/rails]rails--版本rails 2.3.5[~/code/rails]rails种子创建。。。创建db/seeds.rb