1

我一直在关注有关如何从 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

任何帮助、建议或提示将不胜感激。

4

2 回答 2

1

我能够自己解决这个问题。

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

它与 PostgreSQL 的语法无关。

于 2011-09-29T13:19:02.597 回答
0

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

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

于 2011-09-28T10:55:31.143 回答