无法使用heroku在生产中生成数据 [英] Cannot seed data in production using heroku
问题描述
之前我曾经发布过这个问题,但我没有得到任何解决我的问题的答案。因此,我正在重新发布此问题。
我正在使用heroku部署我的rails应用程序。我尝试通过运行命令 heroku run rake db:seed。
来在生产中播种一些数据。但是,该命令不起作用。我无法在生产中播种文件。 seeds.rb
文件在下面给出。
#此文件应该包含使用其默认值对数据库进行种子处理所需的所有记录创建。
#然后可以使用rake db:seed加载数据(或者使用db:setup创建数据库旁边的数据)。
$ b $示例:
#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,
状态: 状态,
国: state,
cities:state)
end
$ heroku在⬢应用种子...起来,run.4751
的ActiveRecord :: SchemaMigration负载(2.0ms)选择 schema_migrations * FROM schema_migrations:运行耙分贝:种子
上运行耙分贝。 p>
我运行 heroku restart
,但这些对象不会播种到生产数据库中。我已经尝试在开发中播种这个文件,并且它完美地工作。我不确定有什么问题。
下面给出了heroku日志-t文件。
2016 -06-22T00:50:58.882699 + 00:00 heroku [api]:使用命令`bundle exec rake db:seed`启动进程*******@gmail.com
2016-06-22T00 :51:07.986301 + 00:00 heroku [run.1041]:等待客户
2016-06-22T00:51:08.026539 + 00:00 heroku [run.1041]:用命令`bundle exec rake db :种子'
2016-06-22T00:51:08.157630 + 00:00 heroku [run.1041]:状态从开始变为上升
2016-06-22T00:51:12.891248 + 00:00 heroku [run.1041]:从状态改变为状态
2016-06-22T00:51:12.881329 + 00:00 heroku [run.1041]:状态0退出进程
我将database.yml文件和seeds.rb文件作为gitignore的一部分。我不确定这是否是问题的原因。我很确定它没有。
seeds.rb
应该在存储库中, code> rails 将其种子。如果没有 seeds.rb
, rails
不会抱怨该文件丢失,而只是完成 rake db:seed
任务没有任何错误。
因此,请确保从 .gitignore $>中删除
seeds.rb
c $ c>,将它添加到 git
中,并使用 git add --force db / seeds.rb
和 git push
它到版本库。
I had posted this question before but I haven't got any answers that solved my problem. Therefore, I am reposting this question.
I am using heroku to deploy my rails app. I am trying to seed some data in the production by running the command heroku run rake db:seed.
However, the command is not working. I am not able to seed files in production. The seeds.rb
file is given below.
#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 run rake db:seed Running rake db:seed on ⬢ app... up, run.4751 ActiveRecord::SchemaMigration Load (2.0ms) SELECT "schema_migrations".* FROM "schema_migrations"
I run heroku restart
but the objects aren't seeded in the production database. I have tried seeding this file in development and it works perfectly. I am not sure what's wrong.
The heroku logs -t file is given below.
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
I have the database.yml file and seeds.rb files as part of gitignore. I am not sure if that might be the cause of the problem. I am pretty sure its not.
seeds.rb
should be in the repository in order for rails
to seed it. If there is no seeds.rb
, rails
doesn't complain that the file is missing, instead it just completes the rake db:seed
task with out any error.
So make sure you remove the seeds.rb
from the .gitignore
, add it to the git
with git add --force db/seeds.rb
and git push
it to the repository.
这篇关于无法使用heroku在生产中生成数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!