I created a new Rails project without database (rails new myApp -O). How can I add a Postgresql database now ?
1 Answer
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?) 4 Comments
Sergio Tulentsev
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.
Rockwell Rice
I totally agree, easier to just rebuild if that is an option
romss182
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!
Rockwell Rice
Hopefully my answer gets you there but I could be missing something buried somewhere for sure.