9928
herokuでデプロイまではできたのですが、heroku run rake db:migrateをすると  
エラーがでてしまいます。  
昨夜から色々やってみたのですが、どうにもわかりません

6行目はActiveAdmin.routes(self)

> devise_for :admin_users, ActiveAdmin::Devise.config  
>  ActiveAdmin.routes(self)

### git push heroku master

```

    remote: -----> Discovering process types
    remote:        Procfile declares types -> (none)
    remote:        Default types for Ruby  -> console, rake, web, worker
    remote: 
    remote: -----> Compressing... done, 45.8MB
    remote: -----> Launching... done, v6
    remote:        https://afternoon-caverns-3384.herokuapp.com/ deployed to Heroku
    remote: 
    remote: Verifying deploy.... done.
    To https://git.heroku.com/afternoon-caverns-1543.git
     * [new branch]      master -> master
    
```

### heroku run rake db:migrate

```

    hogehoge-no-MacBook-Air:jaco-ver4.0.0 hoge$ heroku run rake db:migrate
    Running `rake db:migrate` attached to terminal... up, run.6083
    PG::Error: ERROR:  relation "items" does not exist
    LINE 5:                WHERE a.attrelid = '"items"'::regclass
                                              ^
    :               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                         pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                    FROM pg_attribute a LEFT JOIN pg_attrdef d
                      ON a.attrelid = d.adrelid AND a.attnum = d.adnum
                   WHERE a.attrelid = '"items"'::regclass
                     AND a.attnum > 0 AND NOT a.attisdropped
                   ORDER BY a.attnum
    
    rake aborted!
    ActiveAdmin::DatabaseHitDuringLoad: Your file, app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb (line 822), caused a database error while Active Admin was loading. This is most common when your database is missing or doesn't have the latest migrations applied. To prevent this error, move the code to a place where it will only be run when a page is rendered. One solution can be, to wrap the query in a Proc.Original error message: PG::Error: ERROR:  relation "items" does not exist
    LINE 5:                WHERE a.attrelid = '"items"'::regclass
                                              ^
    :               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                         pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                    FROM pg_attribute a LEFT JOIN pg_attrdef d
                      ON a.attrelid = d.adrelid AND a.attnum = d.adnum
                   WHERE a.attrelid = '"items"'::regclass
                     AND a.attnum > 0 AND NOT a.attisdropped
                   ORDER BY a.attnum
    /app/vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-7e72b7881eb6/lib/active_admin/error.rb:43:in `rescue in capture'
    /app/vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-7e72b7881eb6/lib/active_admin/error.rb:41:in `capture'
    /app/vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-7e72b7881eb6/lib/active_admin/application.rb:203:in `load'
    /app/vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-7e72b7881eb6/lib/active_admin/application.rb:195:in `block in load!'
    /app/vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-7e72b7881eb6/lib/active_admin/application.rb:195:in `each'
    /app/vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-7e72b7881eb6/lib/active_admin/application.rb:195:in `load!'
    /app/vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-7e72b7881eb6/lib/active_admin/application.rb:217:in `routes'
    /app/vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-7e72b7881eb6/lib/active_admin.rb:78:in `routes'
    /app/config/routes.rb:6:in `block in <top (required)>'
    /app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `instance_exec'
    /app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `eval_block'
    /app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:315:in `draw'
    /app/config/routes.rb:1:in `<top (required)>'
    /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
    /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `block in load'
    /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
    /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `each'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:16:in `reload!'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/file_update_checker.rb:75:in `call'
    /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/file_update_checker.rb:75:in `execute'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:27:in `updater'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/initializable.rb:30:in `instance_exec'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/initializable.rb:30:in `run'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/initializable.rb:55:in `block in run_initializers'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/initializable.rb:54:in `run_initializers'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application.rb:300:in `initialize!'
    /app/config/environment.rb:5:in `<top (required)>'
    /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
    /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
    /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application.rb:276:in `require_environment!'
    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application.rb:389:in `block in run_tasks_blocks'
    Tasks: TOP => db:migrate => environment
    (See full trace by running task with --trace)
    
```
CC BY-SA 3.0
2015-05-07T13:09:31.723
9903
2015-05-08T09:32:57.060
2015-05-08T04:39:25.367
9161
9161
question
ruby-on-rails heroku
heroku run rake db:migrate を実行すると relation does not exist というエラー
以下のコマンドを実行してから、再度、`heroku run rake db:migrate` を実行してみては、どうでしょう？

```

    heroku pg:reset DATABASE
    
```
CC BY-SA 3.0
2015-05-07T16:24:55.030
9918
2015-05-07T16:24:55.030
9508
9903
answer
エラーメッセージを見るに、ActiveAdminがMigration実行前にテーブルを読みにいっているようですね。  
ネットでも同じようなエラー報告がいくつか挙がっていました。

スタックトレースを見ると

```

    /app/config/routes.rb:6:in `block in <top (required)>'
    
```

とあるので、`routes.rb`の6行目で何かしらActiveAdminが動き始める処理が書かれているようです。

なので`routes.rb`の6行目前後も追記してください。

あと、ActiveAdminが関連しそうなコードをいったんコメントアウトしろ、みたいな回答もあります。

<https://stackoverflow.com/a/20322552/1058763>

具体的にどこになるのかはアプリによって異なると思いますが、ActiveAdminが自動的に呼び出されそうな処理はいったんコメントアウトすると良いかもしれません。

## EDIT

追記ありがとうございます。  
追記はしてもらったんですが、僕自身はActiveAdminを触ったことがないのでこのコードが何をやっているのかよくわからなかったりします ^^;

当てずっぽうな回答ですいませんが、以下のような作業を試してみてください。

  1. 6行目をコメントアウトしてコミット（できれば5行目も？ActiveAdminの名が付いている箇所は怪しいです）
  2. Herokuにデプロイ
  3. Herokuでdb:migrate （ここでmigrateが成功することを期待）
  4. 1でコメントアウトしたところを元に戻す。
  5. Herokuにデプロイ
  6. Herokuで動作確認
CC BY-SA 3.0
2015-05-08T00:27:35.010
9928
2015-05-08T09:32:57.060
2017-05-23T12:38:56.083
-1
85
9903
answer