无法使用heroku在生产数据库中播种数据

时间:2016-06-13 00:53:53

标签: ruby-on-rails 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 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 isn'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. 

running heroku run rake db:setup gives me the following error

DETAIL:  User does not have CONNECT privilege.
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/app/vendor/ruby-2.2.4/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/app/vendor/ruby-2.2.4/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'

I also get the following errors.
psql:/app/db/structure.sql:955: ERROR:  multiple primary keys for table "mailboxer_conversation_opt_outs" are not allowed
psql:/app/db/structure.sql:963: ERROR:  multiple primary keys for table "mailboxer_conversations" are not allowed
psql:/app/db/structure.sql:971: ERROR:  multiple primary keys for table "mailboxer_notifications" are not allowed
psql:/app/db/structure.sql:979: ERROR:  multiple primary keys for table "mailboxer_receipts" are not allowed
psql:/app/db/structure.sql:987: ERROR:  multiple primary keys for table "managers" are not allowed
psql:/app/db/structure.sql:995: ERROR:  multiple primary keys for table "pg_search_documents" are not allowed
psql:/app/db/structure.sql:1003: ERROR:  multiple primary keys for table "pictures" are not allowed
psql:/app/db/structure.sql:1011: ERROR:  multiple primary keys for table "requests" are not allowed
psql:/app/db/structure.sql:1027: ERROR:  multiple primary keys for table "scoreboards" are not allowed
psql:/app/db/structure.sql:1035: ERROR:  multiple primary keys for table "statuses" are not allowed
psql:/app/db/structure.sql:1043: ERROR:  multiple primary keys for table "team_matches" are not allowed
psql:/app/db/structure.sql:1051: ERROR:  multiple primary keys for table "team_members" are not allowed
psql:/app/db/structure.sql:1059: ERROR:  multiple primary keys for table "teams" are not allowed
psql:/app/db/structure.sql:1067: ERROR:  multiple primary keys for table "topics" are not allowed
psql:/app/db/structure.sql:1075: ERROR:  multiple primary keys for table "users" are not allowed
psql:/app/db/structure.sql:1082: ERROR:  relation "index_categories_on_scoreboard_id" already exists
psql:/app/db/structure.sql:1089: ERROR:  relation "index_documents_on_category_id" already exists
psql:/app/db/structure.sql:1096: ERROR:  relation "index_events_on_scoreboard_id" already exists
psql:/app/db/structure.sql:1103: ERROR:  relation "index_favourites_on_scoreboard_id" already exists
psql:/app/db/structure.sql:1110: ERROR:  relation "index_favourites_on_user_id" already exists
psql:/app/db/structure.sql:1117: ERROR:  relation "index_favourites_on_user_id_and_scoreboard_id" already exists
psql:/app/db/structure.sql:1124: ERROR:  relation "index_invitations_on_scoreboard_

我想我正在运行已经存在的迁移文件。结果,我得到了一个唯一性错误。

2 个答案:

答案 0 :(得分:0)

我认为您有待迁移的迁移。你可以尝试:

Heroku run rake db:migrate db:seed

答案 1 :(得分:0)

尝试以下步骤

heroku run rake db:schema:load
heroku run rake db:migrate
heroku run rake db:seed
相关问题