SelinaLaveryDev / Project4-Budget-Plan-pal

Budget Plan Pal, SEI Project 04 at General Assembly. A full-stack budgeting app made using Ruby on Rails, PostgreSQL, Devise authentication and SASS. Solo project built in 6 days.
https://morning-anchorage-14468.herokuapp.com/
0 stars 0 forks source link

PG::UndefinedTable: ERROR: relation “categories” does not exist #2

Open SelinaLaveryDev opened 1 year ago

SelinaLaveryDev commented 1 year ago

Hi Usman,

I am still having problems with the deployment of my Project 4. My budget app has two tables, a User table and a Transactions table. I used to have a Categories table but deleted it through the CLI, i then created the Transactions table. I have searched my vs code for any traces of the old category table but cannot find any.

I tried resetting the database and then migrated again but still getting this error:

MacBook-Pro:budget_planner_app mp$ heroku run rake db:migrate Running rake db:migrate on ⬢ morning-anchorage-14468... up, run.4376 (Basic) I, [2023-03-16T12:40:32.744229 #2] INFO -- : Migrating to CreateTransactions (20230306233946) == 20230306233946 CreateTransactions: migrating =============================== -- create_table(:transactions) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:

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

On the live heroku site, i can register a user and it appears on the database:

morning-anchorage-14468::DATABASE=> SELECT * FROM users; id | first_name | last_name | email | username | password | created_at | updated_at | password_digest
----+------------+-----------+---------------+----------+----------+----------------------------+----------------------------+-------------------------------------------------------------- 1 | bob | smith | bob@email.com | bob1 | | 2023-03-16 13:06:45.646704 | 2023-03-16 13:06:45.646704 | (1 row)

i can log them in but that is when the error pops up because the code redirects the user to the dashboard, and that is where the error appears because my code references the transactions model which db:migrate refuses to migrate over.

MacBook-Pro:budget_planner_app mp$ heroku run rails db:migrate:status Running rails db:migrate:status on ⬢ morning-anchorage-14468... up, run.1558 (Basic)

database: d9r2emo5u72912

Status Migration ID Migration Name

up 20230305223505 Create users up 20230306004639 Add password digest to users down 20230306233946 Create transactions down 20230307131555 Add category to transactions down 20230307132754 Remove category id from transactions

Have you experienced this before? And do you have any suggestions what to try next?

usmanbashir commented 1 year ago

Hey @sml-40, it seems that there is still a reference to the "categories" table in your code or database schema, even though you have already deleted it. Can you try these suggestions to see if one of them can fix this issue?

  1. Check your database schema file db/schema.rb to see if there is still a reference to the "categories" table. If you find any, let me know.
  2. Check your migration files db/migrate/ to see if there is still a migration that references the "categories" table. If you find any, delete those migrations and run rake db:migrate again.
  3. Check your codebase for any references to the "categories" table. This can be done by searching for the string "categories" across all files. If you find any, remove them.
  4. If you are still unable to find any references to the "categories" table, try dropping and recreating the database using the following commands:

    rake db:drop
    rake db:create
    rake db:migrate

    Mind you, step 4 will won't work on Heroku completely as you can't drop the database from a command. If you want to do it, you have to go to the Add-Ons for the app in the Heroky dashboard to remove the PG database. If you do that, make sure to add a new PG database right after.

Also, is this issue only happening on Heroku or are you also seeing this on your localhost?