ruby-on-rails - 无法使用 heroku 在生产中播种数据

标签 ruby-on-rails ruby heroku

我之前已经发布过这个问题,但我没有得到任何解决我问题的答案。因此,我重新发布这个问题。

我正在使用 heroku 部署我的 Rails 应用程序。我试图通过运行命令 heroku run rake db:seed. 在生产中播种一些数据。但是,该命令不起作用。我无法在生产中播种文件。 seeds.rb 文件如下。

#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' }])
  #Mayor.create(name: 'Emanuel', city: cities.first)

#end


    5.times do              
    Scoreboard.create!(name_of_scoreboard: "scoreboard_abc",
                      name_of_organization: "abcdef",
                      name_of_activity: "ghijklmn",
                      user_id: 1,
                      states: "state",
                      country: "state",
                      cities: "state")
    end

$ heroku 运行 rake db:seed 在 ⬢ app 上运行 rake db:seed...up, run.4751 ActiveRecord::SchemaMigration 加载(2.0 毫秒)SELECT "schema_migrations".* FROM "schema_migrations"

我运行 heroku restart 但对象没有植入生产数据库。我已经尝试在开发中播种这个文件并且它工作得很好。我不确定出了什么问题。

heroku logs -t 文件如下。

2016-06-22T00:50:58.882699+00:00 heroku[api]: Starting process with command `bundle exec rake db:seed` by *******@gmail.com
2016-06-22T00:51:07.986301+00:00 heroku[run.1041]: Awaiting client
2016-06-22T00:51:08.026539+00:00 heroku[run.1041]: Starting process with command `bundle exec rake db:seed`
2016-06-22T00:51:08.157630+00:00 heroku[run.1041]: State changed from starting to up
2016-06-22T00:51:12.891248+00:00 heroku[run.1041]: State changed from up to complete
2016-06-22T00:51:12.881329+00:00 heroku[run.1041]: Process exited with status 0

我有 database.yml 文件和 seeds.rb 文件作为 gitignore 的一部分。我不确定这是否是问题的原因。我很确定它不是。

最佳答案

seeds.rb 应该在存储库中以便 rails 对其进行播种。如果没有 seeds.rbrails 不会提示文件丢失,而只是完成 rake db:seed 任务没有任何错误。

因此请确保从 .gitignore 中删除 seeds.rb,使用 git add 将其添加到 git - -force db/seeds.rbgit push 到存储库。

关于ruby-on-rails - 无法使用 heroku 在生产中播种数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37956727/

相关文章:

ssl - 英雄联盟 :endpoint with GlobalSign ExtendedSSL

django - 从 Heroku 上托管的 Django 项目的子目录运行非 Django 命令?

mysql - Rails 5 Mysql UUID

ruby-on-rails - gem install rails --pre 中的 --pre 做什么?

ruby - 创建和发布您自己的 ruby​​gem 需要哪些步骤?

ruby - 在 Ruby 中解析制表符分隔文件的最佳方法是什么?

ruby-on-rails - 如何在 Ruby on Rails 的 ActiveRecord 查询中加入间接关联?

ruby-on-rails - 超长工作流程的 cucumber 场景

arrays - Ruby:为什么数组中的最后一个元素更改为 1?

ruby-on-rails - Rails:为第3方POST请求禁用CSRF