我正在使用Ruby(1.9.3)和Rails(3.2.2)。我有一个包含一堆虚假数据用于填充我的数据库的任务文件。
以下是我认为可能导致问题的部分任务:
#Create random Tender and populate the db
20.times do |n|
title = "#{Faker::Company.bs()} tender "
company_name = Faker::Company.name
opening_date=Time.at(rand * Time.now.to_i)
closing_date=Time.at(opening_date + ( 8*7*24*60*60)) #add 8 weeks to the deadline
bid_amount= rand(10000..100000)
description=Faker::Lorem.paragraph(sentence_count = 3)
Tender.create!(title: title,
company_name: company_name,
opening_date: opening_date,
closing_date: closing_date,
bid_amount: bid_amount ,
bid_amount: bid_amount ,
description: description )
end
在开发环境中运行正常,但生产数据库上述部分未执行。我在开发环境中使用 gem 'sqlite3', '1.3.5'
,而在生产环境(heroku)中使用 gem 'pg', '0.12.2'
。
当我运行
git push heroku
$ heroku pg:reset SHARED_DATABASE --confirm myapp
$ heroku run rake db:migrate
$ heroku run rake db:populate
db:populate throws an error that says **can't covert Range to Integer.**
有任何想法是什么问题吗?
编辑:bid_amount的数据类型是decimal
$ gem install bundler --pre
指定Heroku的Ruby 1.9.3版本,然后在gem文件中添加ruby '1.9.3'
到gems之前,最后运行$ bundle
。 - Dan Sandland