Home > Back-end >  What are the manual steps I need to take if I can't use the 'rails db:system:change --to=p
What are the manual steps I need to take if I can't use the 'rails db:system:change --to=p

Time:11-28

I'm not understanding what i need to do to update the database.yml.

  1. Do I have to do anything inside a postgresql console?
  2. What do I need to update in my database.yml?

I have been running my development app with sqlite3 up until this point.

Using Rails 5.0.7.2, which came default on my machine at the time.

I have a feeling it has to do with this build error:

Running: rake assets:precompile
       rake aborted!
       Psych::BadAlias: Cannot load `Rails.application.database_configuration`:
       Unknown alias: default
       /tmp/build_6f080167/vendor/bundle/ruby/3.1.0/gems/railties-5.0.7.2/lib/rails/application/configuration.rb:137:in `database_configuration'

Update:

this is what I previously had:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

When I try to go to:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default #<--- psych error should be fixed using &default
  adapter: postgresql #<--- from sqlite
  encoding: utf8
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.psql

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.psql

production:
  <<: *default
  database: db/production.psql

I get an error:

PG::ConnectionBad: FATAL: role "ubuntu" does not exist

Do I need username and password?? Idk what im doing

CodePudding user response:

Assuming you don't need to get any data from your current databases:

  1. Switch from the sqlite3 gem to the pg gem in your Gemfile.

Uninstall the sqlite3 gem if you want: gem uninstall sqlite3

Install the pg gem: gem install pg (or bundle install after adding the gem to your gemfile)

  1. Update your database.yml file:
default: &default #<--- psych error should be fixed using &default
  adapter: postgresql #<--- from sqlite
  encoding: utf8
  pool: 5
  timeout: 5000

... # each database specific settings
  1. Create your database:

rails db:create

If this doesn't work, it'll tell you which migration failed and you can see what table or column data was sqlite specific (but it'd be a rare case)

  1. Remove old sqlite database files on your machine

Database file locations really depend on how you installed sqlite, but check /usr/bin and be careful to only delete the test and development databases for this app (Mac uses SQlite for some things, so don't delete those files by accident). This SO post has other locations where your SQlite databases could be located.

  • Related