0

I have been having this same issue with Heroku deployment now for two days. So much so I have considered just trying to use OpenShift instead, but I am reading Ruby On Rails Tutorial, Second Edition, by Michael Hartl and as you all probably know, they use Heroku. My errors have been deep and involved, so much so I have considered starting over but I feel like I will just end up back at this issue.

As it stands, I read: https://devcenter.heroku.com/articles/sqlite3

If you are starting a new Rails app, you can make postgres the default database by running:

$ rails new -d postgresql

When I do this, this is what I encounter:

$ rails new -d postgresql
Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.
2
  • 1
    the article clearly states 'when starting a new Rails app', not 'when converting an existing app'. Commented Dec 11, 2013 at 15:25
  • I am new to this. I assumed since I have just started the app that it was new, rather than existing. Now looking at it I suppose it is existing. Thanks. Commented Dec 11, 2013 at 15:57

1 Answer 1

1
$ rails new

Initializes a new Rails application. If you already have an existing Rails application and you want to switch to PostgreSQL skip that like and simply update the Gemfile.

Edit your Gemfile and remove this line:

gem 'sqlite3'

Replace with this line:

gem 'pg'

You will also need to update the configuration file as explained in the article. The Heroku article Getting Started with Rails covers how to convert an existing app.

Moreover, you will have to install PostgreSQL locally, create the database and reload the schema. You will find several articles containing the list of commands required to perform such tasks.

You could potentially avoid installing PostgreSQL locally if you use SQLite for development and PostgreSQL for production, however this is not recommended.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a ton for the help. I edited the Gemfile appropriately, as well, I have edited the config file. Now I am at the Install PostgresSQL portion locally, I however don't have much working here. I tried to do a bundle install to hopefully copy the Gemfile to the Gemfile.lock, but now that's also failing. Undefined local variable or method `‘pg’' for Gemfile from /Users/cory/rails_projects/first_app/Gemfile:7
Make sure the syntax of your gemfile is correct. bundler.io/v1.3/gemfile.html You may need to study a little bit of Ruby and Rails to better understand what's going on in your app.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.