【发布时间】:2019-10-05 08:02:55
【问题描述】:
我在 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')
【问题讨论】:
-
“运行 db:seed 时,服务器返回 http 500 错误”是什么意思? HTTP 响应代码来自 HTTP 请求,但
db:seed不发出 HTTP 请求。 -
感谢您的回复。当我运行“heroku run db: migrate”时,它会迁移我的数据库和所有表,但数据是空的。运行“heroku run rails db:seed”后,在heroku中打开应用程序时,浏览器返回错误500。你认为我应该在seeds.rb中进行一些调整吗?我把我的seeds.rb 代码放在了编辑中
-
哦。所以
heroku run rails db:seed“工作”,在它成功完成的意义上。 HTTP 500 是一个通用的服务器端错误消息。您的日志中有什么(尝试运行heroku logs)?
标签: ruby-on-rails postgresql heroku rake heroku-postgres