我有一个 rake 任务来填充表格。
如下:
namespace :db do
desc "fill in the database with icons data"
task :populate_icons => :environment do
make_types
make_templates
make_categories
make_greeting_icons
make_user_icons
end
end
def make_types
Type.delete_all
types = %w{Classic Popular Children Animals}
types.each do |type|
Type.create!(:name => type, :adult => false) #1
end
end
我无法删除数据库,因为某些表中将包含用户数据。
当我重新播种表时,我需要在 1 处重新启动 id。
我怎样才能在 Rails 中做到这一点?