'Rake db:seed'命令在heroku中返回http错误500

时间:2019-05-18 03:21:25

标签: ruby-on-rails postgresql heroku rake heroku-postgres

在Heroku上的Rails中部署api时遇到问题。在开发环境中,它可以完美运行,并且通过db:seed放置的数据位于数据库中。在heroku上进行部署后,我运行了db:migrate命令,并且银行为空,并且在运行db:seed时,服务器返回http 500错误。我做错了什么吗?是否可以在heroku中使用db:seed?

Product.destroy_all
   ProductCategory.destroy_all
   Restaurant.destroy_all
   Category.destroy_all


   path_image = 'public/images/categories/mexican.jpg'
   c = Category.create(id: 1, title: 'mexican')
   c.image.attach(io: File.open(path_image), filename: 'mexican.jpg')

   path_image = 'public/images/categories/italian.jpeg'
   c = Category.create(id: 2, title: 'italian')
   c.image.attach(io: File.open(path_image), filename: 'italian.jpeg')

   path_image = 'public/images/categories/japonese.jpeg'
   c = Category.create(id: 3, title: 'japanese')
   c.image.attach(io: File.open(path_image), filename: 'japanese.jpeg')

   path_image = 'public/images/categories/vegan.jpeg'
   c = Category.create(id: 4, title: 'vegan')
   c.image.attach(io: File.open(path_image), filename: 'vegan.jpeg')


2 个答案:

答案 0 :(得分:0)

尝试,heroku运行rails db:seed

答案 1 :(得分:0)

首先请确保您执行heroku rails db:migrate 然后执行heroku rails db:seed

如果您是直接在heroku终端上编写,则不需要{hero“只是rails db:migraterails db:seed