4

I am trying to configure a database created in sqlite3 with a Ruby on Rails project that I just started. Anyone that can help me? So the database have already been created in the Command line.

Cannot find the right commands to use in the command line! New to this.

Thanks!

3
  • Please describe more specifically your problem. If you have already created the database, the only Rails configuration you need is the database.yml file (and the appropriate model classes); there is no commands to use in the command line. Commented May 20, 2015 at 8:52
  • Configure means, there is a one file in rails project, /config/database.yml, put the details there and refer guides.rubyonrails.org Commented May 20, 2015 at 8:53
  • Thanks for this peeps! Then I actually had done it already! Commented May 20, 2015 at 8:58

4 Answers 4

1

A 'sqlite3' gem should be in gemfile, By default rails added a gem 'sqlite3' in your gem file, when we generate a new rails app.

put the following code in your config/database.yml file :

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000
production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000
Sign up to request clarification or add additional context in comments.

Comments

0

Open config/database.yml

Edit setting: change username/password and database name for the development environment with you Sqlite database and restart server

Eg:

  development:
    adapter: sqlite3
    encoding: utf8
    database: [DB name]
    username: [your username]
    password: [your password]
    host: [host name]

Comments

0

Make sure that gem file contains gem 'sqlite3'

In config/database.yml

 development:
   adapter: sqlite3
   database: db/development.sqlite3
   pool: 5
   timeout: 5000

Comments

0

When you create a new rails project, you can specify which database you want to use, example:

rails new your_app_name --database=sqlite3

this will directly generate this configuration under config/database.yml:

default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 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

Comments

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.