【问题标题】:Cannot seed data in the production database using heroku无法使用 heroku 在生产数据库中播种数据
【发布时间】:2016-06-13 00:53:53
【问题描述】:

我正在使用 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_

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

【问题讨论】:

    标签: ruby-on-rails heroku


    【解决方案1】:

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

    Heroku run rake db:migrate db:seed
    

    【讨论】:

    • 我依次运行 heroku pg:reset DATABASE、heroku 运行 rake db:migrate 和 heroku db:seed。迁移不应该挂起,因为我运行了 heroku run rake db:migrate。我试过你的命令,但没有用。
    【解决方案2】:

    试试这些步骤,

    heroku run rake db:schema:load
    heroku run rake db:migrate
    heroku run rake db:seed
    

    【讨论】:

    • schema.rb 文件对我来说不存在。我已将其更改为 structure.sql,因为我使用 tsvector 列进行 postgresql 全文搜索。第一个命令不起作用,因为该文件不存在。我试过了,我得到了以下错误。 /app/db/schema.rb 还不存在。运行rake db:migrate 来创建它。
    • 你可以尝试执行 heroku run rake db:setup 然后运行 ​​heroku run rake db:seed
    猜你喜欢
    • 1970-01-01
    • 2018-12-06
    • 2011-11-19
    • 2014-01-25
    • 2014-03-01
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多