【问题标题】:heroku PGError: already exists 500 We're sorry, but something went wrongheroku PGError:已经存在 500 很抱歉,但出了点问题
【发布时间】:2012-11-27 08:29:47
【问题描述】:

已解决:这个问题是如何神秘消失的,这是 heroku 生成的 url

http://pacific-escarpment-9949.herokuapp.com/

如果有人能详细说明为什么它在 30 分钟前给出了错误页面,我将不胜感激。

它在本地运行良好。但是当我将它推送到 Heroku 时,它给出了这个错误。

我认为它与数据库有关,因为我使用了命令:

rails generate migration add_user_id_to_post integer (pseudocode, it worked fine)

我已经运行了:$ heroku run rake db:migrate

应该是主页的页面显示: 很抱歉,出了点问题。

我之前遇到过这个问题,但是当我运行 heroku run rake db:migrate 时,它​​解决了这个问题。但这次不是。请帮助。我已经被困了3个小时了。谢谢。

这是我在 git hub 上的 repo:https://github.com/nixor/blog

请原谅我的菜鸟,所有这些对我来说都是 2 周前的新手。

nixor@unix:$ heroku run rake db:migrate
    Running `rake db:migrate` attached to terminal... up, run.1
    DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
    DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
    Connecting to database specified by DATABASE_URL
    Migrating to CreatePosts (20121124111726)
    ==  CreatePosts: migrating ====================================================
    -- create_table(:posts)
    NOTICE:  CREATE TABLE will create implicit sequence "posts_id_seq" for serial column "posts.id"
    NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "posts_pkey" for table "posts"
       -> 0.0215s
    ==  CreatePosts: migrated (0.0216s) ===========================================
    
    Migrating to CreateUsers (20121126134513)
    ==  CreateUsers: migrating ====================================================
    -- create_table(:users)
    NOTICE:  CREATE TABLE will create implicit sequence "users_id_seq" for serial column "users.id"
    NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "users_pkey" for table "users"
       -> 0.0121s
    ==  CreateUsers: migrated (0.0122s) ===========================================
    
    Migrating to AddUserIdToPosts (20121126173652)
    ==  AddUserIdToPosts: migrating ===============================================
    -- add_column(:posts, :user_id, :integer)
    rake aborted!
    An error has occurred, this and all later migrations canceled:
    
    PGError: ERROR:  column "user_id" of relation "posts" already exists
    : ALTER TABLE "posts" ADD COLUMN "user_id" integer
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:652:in `async_exec'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:652:in `block in execute'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
    /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `execute'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1025:in `add_column'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:466:in `block in method_missing'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:438:in `block in say_with_time'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:438:in `say_with_time'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:458:in `method_missing'
    /app/db/migrate/20121126173652_add_user_id_to_posts.rb:3:in `change'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:407:in `block (2 levels) in migrate'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:407:in `block in migrate'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:389:in `migrate'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:528:in `migrate'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:775:in `call'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:775:in `block in ddl_transaction'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/transactions.rb:208:in `transaction'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:775:in `ddl_transaction'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:719:in `block in migrate'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:700:in `each'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:700:in `migrate'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:570:in `up'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/migration.rb:551:in `migrate'
    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>'
    Tasks: TOP => db:migrate
    (See full trace by running task with --trace)

【问题讨论】:

标签: ruby-on-rails heroku


【解决方案1】:

Adding user_id to posts 没有意义,因为 user_id 已经在 first migration 中定义。 Postgres 正确地引发了错误。

删除迁移应该是安全的,因为它不会进行任何更改。

【讨论】:

  • 但这是因为我在那里手动写了user_id。这有什么区别吗?你的意思是 git rm 吗?
  • 是的。每个迁移文件都是一组关于如何更改数据库的说明。您不应该因为新的更改而返回并编辑旧的迁移。
  • 谢谢。我想投票,但直到我有 15 分才能投票。我以后可能会回来这样做。
  • 如果我帮助你解决了你的问题,你可以接受答案=)
  • 这样做了。你也可以再检查一下帖子吗,我已经编辑了……现在有点好笑。
猜你喜欢
  • 2014-01-22
  • 2016-03-05
  • 2012-07-29
  • 2012-04-19
  • 2012-06-19
  • 1970-01-01
  • 2012-05-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多