【问题标题】:Heroku - Rails 3 to 3.1 migration issues with PostgreSQL: relation "users" does not existHeroku - PostgreSQL 的 Rails 3 到 3.1 迁移问题:关系“用户”不存在
【发布时间】:2011-09-28 10:19:46
【问题描述】:

我一直在关注有关如何从 Rails 3 迁移到 3.1 并使其在 Heroku 上运行的文档。我使用了这里给出的手动升级技术:http://webtempest.com/upgrade-rails-3-to-3-1/

我已经取得了一些缓慢的进展,但让它与 Heroku 一起工作一直很痛苦。我的应用程序目前在本地使用 rails 3.1 运行良好。我可能应该让你知道,在开发模式下,我使用的是 mysql(仅仅是因为可以选择使用 sequel pro,而且我还没有完全弄清楚如何在本地使用 postgres)。问题是,我在 rails 3.0 中将我的应用程序推送到 heroku 并在 postgres 和本地使用 mysql 时都没有问题。它一直运行良好。但是,既然我已经使用 heroku cedar 堆栈迁移到 3.1,我在关注 heroku 文档时遇到了以下问题:http://devcenter.heroku.com/articles/rails31_heroku_cedar

以下是我在将代码推送到 heroku 后尝试迁移或重置应用程序的数据库以及重新启动应用程序时不断遇到的错误。

Running rake db:reset attached to terminal... up, run.9
Couldn't drop hvifyyqdjs : #<ActiveRecord::StatementInvalid: PGError: ERROR:  must be owner of database hvifyyqdjs
: DROP DATABASE IF EXISTS "hvifyyqdjs">
hvifyyqdjs already exists
rake aborted!
PGError: ERROR:  relation "users" does not exist
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"users"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

关于如何克服这个问题的任何想法?我正在为这里提到的“用户”使用设计插件。我对这个问题的研究使我早些时候相信我的迁移可能没有正确创建用户表,但是我的第一个迁移文件确实创建了用户表

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable

      # t.encryptable
      # t.confirmable
      # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
      # t.token_authenticatable


      t.timestamps
    end

    add_index :users, :email,                :unique => true
    add_index :users, :reset_password_token, :unique => true
    # add_index :users, :confirmation_token,   :unique => true
    # add_index :users, :unlock_token,         :unique => true
    # add_index :users, :authentication_token, :unique => true
  end

  def self.down
    drop_table :users
  end
end

尝试在 heroku 上重新启动应用程序时,这是我在日志中看到的内容

2011-09-28T09:55:08+00:00 app[web.1]: => Booting WEBrick
2011-09-28T09:55:08+00:00 app[web.1]: => Rails 3.1.0 application starting in production on http://0.0.0.0:33603
2011-09-28T09:55:08+00:00 app[web.1]: => Call with -d to detach
2011-09-28T09:55:08+00:00 app[web.1]: => Ctrl-C to shutdown server
2011-09-28T09:55:08+00:00 app[web.1]: Exiting
2011-09-28T09:55:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:962:in `async_exec': PGError: ERROR:  relation "users" does not exist (ActiveRecord::StatementInvalid)
2011-09-28T09:55:08+00:00 app[web.1]: :             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
2011-09-28T09:55:08+00:00 app[web.1]:               FROM pg_attribute a LEFT JOIN pg_attrdef d
2011-09-28T09:55:08+00:00 app[web.1]:                 ON a.attrelid = d.adrelid AND a.attnum = d.adnum
2011-09-28T09:55:08+00:00 app[web.1]:              WHERE a.attrelid = '"users"'::regclass
2011-09-28T09:55:08+00:00 app[web.1]:                AND a.attnum > 0 AND NOT a.attisdropped
2011-09-28T09:55:08+00:00 app[web.1]:              ORDER BY a.attnum
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:962:in `exec_no_cache'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:551:in `block in exec_query'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:239:in `log'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:550:in `exec_query'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1061:in `column_definitions'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:740:in `columns'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `block (2 levels) in initialize'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:185:in `with_connection'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:92:in `block in initialize'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:706:in `yield'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:706:in `default'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:706:in `columns'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:722:in `column_names'
2011-09-28T09:55:08+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base

非常感谢任何帮助、建议或提示。

【问题讨论】:

    标签: ruby-on-rails postgresql heroku ruby-on-rails-3.1 rails-postgresql


    【解决方案1】:

    我自己解决了这个问题。

    我的一个初始化文件正在执行find_or_create_by_id,它在开发时运行良好,但由于我现在正在部署一个全新的应用程序,因此缺少表是该错误的根源,并且还阻止了迁移命令从运行和创建丢失的表。

    与PostgreSQL的语法无关。

    【讨论】:

      【解决方案2】:

      看第一条错误信息:“ERROR: must be owner of database hvifyyqdjs”

      您(或您的程序)不允许删除它。

      【讨论】:

      • hvifyyqdjs 错误行就在那里,因为我使用了重置命令。当我尝试重置应用程序或其他任何内容时,它不会出现。在所有其他情况下,我都会遇到上面提到的“用户”参考错误。检查我刚刚添加的 heroku 的新日志,看看我重新启动应用程序时会发生什么。似乎 postgresql_adapter.rb 出了点问题
      • 但最终结果是您的应用无法删除数据库,也无法重新创建它,并且找不到它期望的对象,或者具有不同的结构。跨度>
      • 我明白了。我的猜测是,hvifyyqdjs 似乎是一个与 Heroku 相关的数据库,所以我无法完全访问它。正如 Erwin 所指出的,问题在于使用“用户”的WHERE a.attrelid = '"users"'::regclass 行。引号中的双引号。为什么它使用它以及如何改变它是我不知道的并且可以使用帮助。
      • BTW:在数据库出错的情况下,通常最好检查数据库日志文件。框架倾向于错误地弯曲错误并导致大量级联错误。这也是我“看第一个错误,忽略其余部分”反射的本质。
      猜你喜欢
      • 2012-03-25
      • 2017-02-19
      • 1970-01-01
      • 2015-08-30
      • 1970-01-01
      • 2012-06-19
      • 2011-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多