-1

I know there are numerous topics on this. I have tried them all to no success. Note, I do not need to maintain my previous data. I just need my app to work in Heroku.

Following this guide, this is one thing I've tried Change from SQLite to PostgreSQL in a fresh Rails project

So I have my application that works using sqlite3.

Go into 'gemfile' and change

gem 'sqlite3' into gem 'pg'

run $ bundle in terminal (to change Gemfile.lock)

Go to my database.yml file and replace it with

development:
  adapter: postgresql
  encoding: utf8
  database: project_development
  pool: 5
  username:
  password:

test: &TEST
  adapter: postgresql
  encoding: utf8
  database: project_test
  pool: 5
  username:
  password:

production:
  adapter: postgresql
  encoding: utf8
  database: project_production
  pool: 5
  username:
  password:

cucumber:
  <<: *TEST

I then pushed this to github.

On the Heroku website I connect the github directory to my app and deploy it.

It successfully deploys but the page only says

We're sorry, but something went wrong.
If you are the application owner check the logs for more information.

I am pretty certain I am missing a step as whenever I try to run it on my local machine it says

ActiveRecord::NoDatabaseError

FATAL: database "project_development" does not exist

Extracted source (around line #661):

659 rescue ::PG::Error => error
660   if error.message.include?("does not exist")
661     raise ActiveRecord::NoDatabaseError.new(error.message, error)
662   else
663     raise
664   end

--

EDIT

When I input

heroku run rake db:create

I get the response

▸ Error: No app specified ▸ Usage: heroku run --app APP ▸ We don't know which app to run this on. ▸ Run this command from inside an app folder or specify which app to use with --app APP

When I run

heroku run rake db:create -app nguyen-andrew-a2

I get the response

Running rake db:create nguyen-andrew-as2 on ⬢ pp... !!! ▸ Couldn't find that app. Macbook-Pro-5:try2 andrew$

--

On my local machine, after running it the page now says

fe_sendauth: no password supplied

Extracted source (around line #651):
649 # connected server's characteristics.
650 def connect
651    @connection = PGconn.connect(@connection_parameters)
652
653    # Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
654    # PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision
Community
  • 1
  • 1
Andrew Nguyen
  • 29
  • 1
  • 5
  • Possible duplicate of [Change from SQLite to PostgreSQL in a fresh Rails project](http://stackoverflow.com/questions/6710654/change-from-sqlite-to-postgresql-in-a-fresh-rails-project) – thesecretmaster Jun 06 '16 at 10:11

2 Answers2

1

Did you run rake db:create on your local machine and on Heroku? Try these steps:

  • bundle exec rake db:create
  • bundle exec rake dg:migrate
  • bundle exec rails s

For Heroku, just add heroku run before any command, like this: heroku run rake db:create, and heroku run rake db:migrate.

1

If you encounter the couldn't find that app error, that means that you passed an invalid app name as the -a, --app option for the heroku command. Valid app names are obtained with the heroku apps command.

I also see that you ran ... -app <app-name> ... instead of ... --app <app-name> ..., which is likely to cause errors. Try the following command replacement:

// before
heroku run rake db:create -app nguyen-andrew-a2
// after
heroku run rake db:create --app nguyen-andrew-a2
Nino Filiu
  • 16,660
  • 11
  • 54
  • 84