Achyut
Achyut

Reputation: 733

Why my active admin shows errors which perfetly worked locally?

I am trying to add admin interface with activeadmin in my rails app. I have successfully completed locally but it gives error after deploying to heroku. I have done all the things which is necessary for database migrations like:

heroku run rake db:create
heroku run rake db:migrate

I have changed the production to see the error:

config.consider_all_requests_local = true

When I navigate to [mysitename].herokuapp.com/admin it gives the error like below:

ActiveRecord::StatementInvalid in ActiveAdmin::Devise::SessionsController#new

PG::UndefinedTable: ERROR: relation "admin_users" does not exist LINE 8: WHERE a.attrelid = '"admin_users"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod, (SELECT c.collname FROM pg_collation c, pg_type t WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation), col_description(a.attrelid, a.attnum) AS comment FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"admin_users"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum

And I clone my heroku and see if admin_users in schema.rb exists or not. I found there is admin_users table in schema.rb.

My routes.rb is:

Rails.application.routes.draw do
  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  devise_for :users
  resources :users, only: :show
  resources :posts do
    resources :comments
    resources :upvotes, only: :create
    resources :downvotes, only: :create
  end
  root 'posts#index'  
end

My active_admin.rb is:

ActiveAdmin.setup do |config|

  config.site_title = "Instapost"

  config.authentication_method = :authenticate_admin_user!

  config.current_user_method = :current_admin_user

  config.logout_link_path = :destroy_admin_user_session_path

  config.comments = false

  config.comments_menu = false

  config.batch_actions = true

  config.localize_format = :long

  config.favicon = 'favicon.ico'

end

I have searched a lot. But any solutions could not solve this problem. If anybody know about this please help me to solve the problem.

Upvotes: 0

Views: 1171

Answers (1)

Achyut
Achyut

Reputation: 733

As I see the error, I tried a lot and finally succeed. The main error is

PG::UndefinedTable: ERROR: relation "admin_users" does not exist

This says that relation admin_users does not exist. It means the migration is trying to change the admin_users which already existed in the table. But actually it does not exist in the table we have to create it.

Hence, in the migration file created by active admin /db/migrate/xxxxxxxxxxxxx_add_devise_to_admin_users.rb, replace change with create as change_table :admin_users do |t| with create_table :admin_users do |t|

Finally, push to the heroku and run heroku run rake db:migrate

Upvotes: 1

Related Questions