Cathrin
Cathrin

Reputation: 51

How to configure a Database in sqlite3 with a Ruby on Rails project

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!

Upvotes: 4

Views: 4644

Answers (4)

Mohamed Hakki
Mohamed Hakki

Reputation: 98

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

Upvotes: 0

uma
uma

Reputation: 2952

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

Upvotes: 1

Prashant4224
Prashant4224

Reputation: 1601

Make sure that gem file contains gem 'sqlite3'

In config/database.yml

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

Upvotes: 0

Sachin R
Sachin R

Reputation: 11876

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]

Upvotes: 0

Related Questions