zeroday
zeroday

Reputation: 11

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

I am trying to run this [https://github.com/ttseng/Build-in-Progress-Web/wiki/1.-Running-Locally][1] and so I installed the required materials and when it comes to the database setup I get this ! I can't really understand what is it? and why I can't deploy this platform locally without the database migration. There are always two pending migration

  20170606002857 AddDeviseToAdmins
  20170606130509 AddUserRefToGoals
` root@debian:/home/zeeroday/github/Build-in-Progress-Web# bundle exec rake db:drop
root@debian:/home/zeeroday/github/Build-in-Progress-Web# bundle exec rake db:setup
-- create_table("activities", {:force=>true})
   -> 0.1371s
-- add_index("activities", ["owner_id", "owner_type"], {:name=>"index_activities_on_owner_id_and_owner_type"})
   -> 0.0910s
-- add_index("activities", ["recipient_id", "recipient_type"], {:name=>"index_activities_on_recipient_id_and_recipient_type"})
   -> 0.0911s
-- add_index("activities", ["trackable_id", "trackable_type"], {:name=>"index_activities_on_trackable_id_and_trackable_type"})
   -> 0.0909s
-- create_table("admin_users", {:force=>true})
   -> 0.1411s
-- add_index("admin_users", ["email"], {:name=>"index_admin_users_on_email", :unique=>true})
   -> 0.0909s
-- add_index("admin_users", ["reset_password_token"], {:name=>"index_admin_users_on_reset_password_token", :unique=>true})
   -> 0.0910s
-- create_table("categories", {:force=>true})
   -> 0.0992s
-- create_table("categorizations", {:force=>true})
   -> 0.0908s
-- add_index("categorizations", ["category_id", "project_id"], {:name=>"index_categorizations_on_category_id_and_project_id", :unique=>true})
   -> 0.0910s
-- add_index("categorizations", ["category_id"], {:name=>"index_categorizations_on_category_id"})
   -> 0.0907s
-- add_index("categorizations", ["project_id"], {:name=>"index_categorizations_on_project_id"})
   -> 0.0910s
-- create_table("collectifies", {:force=>true})
   -> 0.0993s
-- add_index("collectifies", ["collection_id", "project_id"], {:name=>"index_collectifies_on_collection_id_and_project_id", :unique=>true})
   -> 0.0907s
-- add_index("collectifies", ["collection_id"], {:name=>"index_collectifies_on_collection_id"})
   -> 0.0910s
-- add_index("collectifies", ["project_id"], {:name=>"index_collectifies_on_project_id"})
   -> 0.0908s
-- create_table("collections", {:force=>true})
   -> 0.1238s
-- add_index("collections", ["slug"], {:name=>"index_collections_on_slug"})
   -> 0.0742s
-- create_table("comments", {:force=>true})
   -> 0.1249s
-- add_index("comments", ["commentable_id", "commentable_type"], {:name=>"index_comments_on_commentable_id_and_commentable_type"})
   -> 0.0825s
-- add_index("comments", ["user_id"], {:name=>"index_comments_on_user_id"})
   -> 0.0827s
-- create_table("decisions", {:force=>true})
   -> 0.0825s
-- create_table("delayed_jobs", {:force=>true})
   -> 0.1244s
-- add_index("delayed_jobs", ["priority", "run_at"], {:name=>"delayed_jobs_priority"})
   -> 0.0825s
-- create_table("design_files", {:force=>true})
   -> 0.0828s
-- create_table("edits", {:force=>true})
   -> 0.0826s
-- create_table("favorite_projects", {:force=>true})
   -> 0.0910s
-- create_table("follows", {:force=>true})
   -> 0.1492s
-- add_index("follows", ["followable_id", "followable_type"], {:name=>"fk_followables"})
   -> 0.0907s
-- add_index("follows", ["follower_id", "follower_type"], {:name=>"fk_follows"})
   -> 0.0827s
-- create_table("friendly_id_slugs", {:force=>true})
   -> 0.0827s
-- add_index("friendly_id_slugs", ["slug", "sluggable_type"], {:name=>"index_friendly_id_slugs_on_slug_and_sluggable_type", :unique=>true})
   -> 0.0826s
-- add_index("friendly_id_slugs", ["sluggable_id"], {:name=>"index_friendly_id_slugs_on_sluggable_id"})
   -> 0.0825s
-- add_index("friendly_id_slugs", ["sluggable_type"], {:name=>"index_friendly_id_slugs_on_sluggable_type"})
   -> 0.0826s
-- create_table("images", {:force=>true})
   -> 0.1241s
-- create_table("news", {:force=>true})
   -> 0.1822s
-- create_table("placements", {:force=>true})
   -> 0.0909s
-- create_table("projects", {:force=>true})
   -> 0.1740s
-- create_table("projects_users", {:id=>false, :force=>true})
   -> 0.0083s
-- add_index("projects_users", ["project_id", "user_id"], {:name=>"index_projects_users_on_project_id_and_user_id"})
   -> 0.0823s
-- create_table("questions", {:force=>true})
   -> 0.0911s
-- create_table("remarks", {:force=>true})
   -> 0.1241s
-- create_table("sessions", {:force=>true})
   -> 0.1324s
-- add_index("sessions", ["session_id"], {:name=>"index_sessions_on_session_id"})
   -> 0.0825s
-- add_index("sessions", ["updated_at"], {:name=>"index_sessions_on_updated_at"})
   -> 0.0827s
-- create_table("settings", {:force=>true})
   -> 0.1578s
-- add_index("settings", ["target_type", "target_id", "var"], {:name=>"index_settings_on_target_type_and_target_id_and_var", :unique=>true})
   -> 0.0820s
-- create_table("sounds", {:force=>true})
   -> 0.1573s
-- create_table("steps", {:force=>true})
   -> 0.1241s
-- add_index("steps", ["ancestry"], {:name=>"index_steps_on_ancestry"})
   -> 0.0825s
-- create_table("users", {:force=>true})
   -> 0.1492s
-- add_index("users", ["authentication_token"], {:name=>"index_users_on_authentication_token", :unique=>true})
   -> 0.0823s
-- add_index("users", ["confirmation_token"], {:name=>"index_users_on_confirmation_token", :unique=>true})
   -> 0.0826s
-- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})
   -> 0.0908s
-- add_index("users", ["reset_password_token"], {:name=>"index_users_on_reset_password_token", :unique=>true})
   -> 0.0827s
-- add_index("users", ["unlock_token"], {:name=>"index_users_on_unlock_token", :unique=>true})
   -> 0.0826s
-- create_table("versions", {:force=>true})
   -> 0.1491s
-- add_index("versions", ["item_type", "item_id"], {:name=>"index_versions_on_item_type_and_item_id"})
   -> 0.0825s
-- create_table("videos", {:force=>true})
   -> 0.1574s
-- initialize_schema_migrations_table()
   -> 0.1017s
-- assume_migrated_upto_version(20170605230006, ["/home/zeeroday/github/Build-in-Progress-Web/db/migrate"])
   -> 0.8765s
You have 2 pending migrations:
  20170606002857 AddDeviseToAdmins
  20170606130509 AddUserRefToGoals
Run `rake db:migrate` to update your database then try again.
`

I tried many things related to the same error but always the same thing. And before I had the same error but I created an admin user in the DB and so it migrate most of the database except the two above.

Upvotes: 0

Views: 1530

Answers (2)

Roger Perez
Roger Perez

Reputation: 3149

I was having this issue but in my Heroku production environment trying to run Heroku run rails db:migrate -a=[App-name] on my terminal. My DB was working properly before I made the change from

t.string :admin_id to

t.references :admin, foreign_key: true.

Once I changed it back it started working.

Here is the current code for my migration

class CreateUsers < ActiveRecord::Migration[5.2]
  def change
    create_table :users do |t|
      t.string     :username
      t.string     :email
      t.string     :password
      t.string     :wristband_num
      t.integer    :admin_id
      t.integer    :organization_id

      t.timestamps
    end
  end
end

Upvotes: 0

Pavan
Pavan

Reputation: 33552

PG::UndefinedTable: ERROR: relation “admins” does not exist

As the log says you have pending migrations. You should run rake db:migrate to resolve the issue.

Upvotes: 2

Related Questions