4

I created a new Rails project without database (rails new myApp -O). How can I add a Postgresql database now ?

0

1 Answer 1

5

Add the pg gem to your gemfile.

# Use postgresql as the database for Active Record gem 'pg' 

Then, if you do not have it, you will need a database.yml file in your config directory so go there and in the config directory create a fole called database.yml which should look like this.

config/database.yml

default: &default adapter: postgresql encoding: unicode username: your username for your Postgresql access password: your password for your Postgresql access # For details on connection pooling, see rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> development: <<: *default database: The name for your **development** database that you created (probably in PGAdmin?) test: <<: *default database: The name for your **test** database that you created (probably in PGAdmin?) production: <<: *default database: The name for your **production** database that you created (probably in PGAdmin?) 
Sign up to request clarification or add additional context in comments.

4 Comments

One probably must also add a line that active_record to config/application.rb. Config test generators, maybe. And god knows what else. If it's a brand new app, easier to just regenerate.
I totally agree, easier to just rebuild if that is an option
thanks Rockwell and Sergio, I will consider this option (start again the project) but I'll also challenge myself trying to add the db and make things work, I'll probably learn interesting stuff!
Hopefully my answer gets you there but I could be missing something buried somewhere for sure.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.