简体   繁体   中英

How can I change from SQLite database to PostgreSQL database in a working Rails project for localhost?

in database.yml

development:
  adapter: postgresql
  encoding: unicode
  database: demo_test_development
  pool: 5
  username: adarsh
  password: 
  timeout: 5000
  host: localhost
  port: 5432

test:
  adapter: postgresql
  encoding: unicode
  database: demo_test_test
  pool: 5
  username: adarsh
  password: 
  timeout: 5000
  host: localhost
  port: 5432

in gem file

group :development do

    gem 'pg'
    gem 'taps'

end

then I do

1) Bundle install (is working)

2)rake db:setup,db:create,db:migrate(but is not working)

Getting error : could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? Couldn't create 'demo_test_development' database. Please check your configuration.

You need to install postgresql package into your system you can refer to this link for instruction regarding installing postgres all you need to do is execute the following commands

sudo apt-get install postgresql postgresql-contrib

this installs postgres into your system

then you need to create a user with the details that you have mentioned in the database.yml file of your rails application

You can use pgadmin for db browser you can refer to this question for other tools

to install pgadmin3 run the following command

 sudo apt-get install pgadmin3

then configure it with the details like host port etc that you are using(refer to database.yml)

You are using gem 'pg' in development group in gem file.

group :development do

    gem 'pg'
    gem 'taps'

end

Include it in every environment by moving this line out of development group.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM