Rails App Heroku PG::UndefinedTable: ERROR: - ruby-on-rails

I have been searching for 12 hours to a solution to this problem, please can someone help with the following.
Locally my app is working as it should no errors, as soon as I deploy to heroku it just refuses to display the login/sign up pages.
I have tried all my technical ability is capable off. 12 hours of research and i cant find anything.
Puma caught this error: PG::UndefinedTable: ERROR: relation "servers" does not exist
LINE 9: WHERE a.attrelid = '"servers"'::regclass
Couldn't create 'defml5i7le0i08' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.
^

https://github.com/netguru-training/wroclaw-ror-workshops-2015-december/issues/4
The issue was devise only creates a migration and does not create the table.
The solution was to delete migrations, generate the User model first to create the table then run devise MODEL for the routes.

Related

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "posts" does not exist

I am trying to run a scraping task on my local machine that then creates a post in my production database (Heroku and PostgresSQL). For this I am using rails scrape:scrapeWeb RAILS_ENV=production.
Even though this used to work in the past, now I get thrown the following error:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "posts" does not exist
LINE 8: WHERE a.attrelid = '"posts"'::regclass
The line that causes this is this one:
Post.create(user_id: 1, link: link, to_be_checked: true), so it us just a simple Post creation.
Other interesting things:
Reseting the database and trying to run all the migrations again did not help
When I run the line Post.create(user_id: 1, link: link, to_be_checked: true) in my production console (via heroku run rails c), it creates the post perfectly without problems.
Running the task locally on my development database works perfectly.
I cannot run the task on my production server as it uses Kimurai, which doesnt work with heroku.
Thanks so much for any input!

Can't access db after adding to Heroku

I can't access my Postgres tables since putting my app on Heroku. I checked the logs with heroku logs --tail and saw this error
ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "companies" does not exist
I've run as many different rake combinations of drop create migrate seed, and reset as I can think of with no luck.
I created a new endpoint on that app (/api/v1/testing/) and I was able to access that endpoint with no problem.
I am still able to access all of the tables on the db locally when I run rails s.
I don't know which files from my app would be helpful to solve this problem but I am happy to add any detail that would be helpful.
I'm guessing you didn't run:
heroku run rake db:migrate --app your_app_name
(replacing your_app_name, naturally.)

issues with schema.rb file during rails 5 upgrade

After upgrading to Rails 5, I receive an error message like following every time I try to load from schema (set up a new computer on the app, run rails db:test:prepare before running tests, etc.):
ActiveRecord::StatementInvalid: PG::UndefinedObject: ERROR: type "serial" does not exist
LINE 1: SELECT 'serial'::regtype::oid
Searching around isn't yielding much help. The most relevant thread is this one: https://github.com/rails/rails/issues/30298 but I am not trying to run any new migrations, nor does the schema_plus_indexes gem seem to have anything to do with the issue (the two issues described in that thread).
In our case, we don't keep migration files around after they have been run against all databases. Because of this, when working on the upgrade to rails 5, there were 0 migration files present. The issue, it seems, is that rails will only automatically "fix" your schema.rb file for you if you are actually running a migration file (even trying rails db:migrate with no migration files present won't work).
The solution, for us, was to create a blank migration and run rails db:migrate in order to get the schema.rb file properly formatted.

ruby page on Heroku comes up with error: 'we're sorry but something went wrong'

Hi in the last week pushed a ROR rake task to prod and then ran the rake task to update some table fields in heroku.
Everything was seemed fine at the time but this week I did something that I hadn't done in the previous week of creating a new practice or editing one gives an error of 'we're sorry but something went wrong'
The error message I get from running --tail in the terminal says
Completed 500 internal server error in 34ms
ActionView::Template::Error (undefined method 'practices' for nil:NilClass);
This is my production application.
In the staging application I don't get this error.
The 2 environments are supposed to be the same.
Is a migration needed? or failing that how could I work out what is going wrong.
thanks
maggs
Run this command and try
heroku run rake db:migrate
Database
The 2 environments are supposed to be the same. Is a migration needed?
It depends on if you're using the same database in production & development
By default, Heroku gives you a blank PGSQL database, or you can override their DATABASE_URL config variable to use your own db:
heroku config:set DATABASE_URL=mysql://your_database
Recommendation
For now, I would recommend performing a heroku run rake db:migrate on your Heroku database, as this will provide the right data structure for your app
The real problem, though, is you're calling practices on an undefined object (nil:class). To ensure this is not a problem, you either need some logic such as:
unless #variable.nil?
# do something
end
or you need to ensure you're working with the correct data

Transfer database to Heroku

I am trying to transfer my database to Heroku but I with no luck. I followed all steps in this guide: https://devcenter.heroku.com/articles/getting-started-with-rails4
I run heroku run rake db:migrate and it says Runningrake db:migrateattached to terminal... up, run.8685.
After I run heroku open I have access only to empty database and when I try to access some data, error shows: Completed 500 Internal Server Error in 25ms ActionView::Template::Error (undefined method id for nil:NilClass): So, there is no data present online.
What could be a problem? Thank you.
EDIT1:
When I go to a link https://postgres.heroku.com/databases/my-database-name I see this:
Statistics
Plan Dev
Status available
Data Size 6.6 MB
Tables 5
PG Version 9.2.5
Created October 22, 2013 16:45
It says there are 5 tables present and that's true. The problem is it seems these tables are empty. I don't see any option on Heroku website to browse database data. I checked with https://github.com/ddollar/heroku-sql-console, tried a couple of queries and database is empty.
Did your migration successfully ended??
Were you able to saw tables in your database??
If there is problem in your migration try to load it from schema
rake db:schema:load
please check your database status from postgres.heroku.com

Resources