4

Generate a SQlite-based Rails app

 3 years ago
source link: https://www.devroom.io/2006/10/10/generate-a-sqlite-based-rails-app/?utm_campaign=Feed%3A+ariejan+%28ariejan%7Cdevroom.io%29
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Generate a SQlite-based Rails app

Posted: 2006-10-10 - Last updated: 2019-06-05

Tagged general everything rubyonrails databases sqlite features

When you create a Rails application a database.yml files is included with some default configuration for your database. Unfortunately these are defaults for MySQL. If you want to use another database, like SQlite, you’d have to rewrite the entire configuration file. And that’s not what you want!

Luckily, rails is very adapative and we can make it do all the work for us.

When you create a rails application, firstr check out the help message from rails itself.

$ rails –help

When you look closely you’ll see that there’s an option available called ‘–database’. It has the following message attached to it:

Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite2/sqlite3).

Basically, you can specify, when create your rails project, what database type you want to use, and Rails’ll create a matching configuration file for you. When you leave this option out, it defaults to MySQL.

As you can see there are several databases supported, including SQLite. In order to create a new rails project with SQlite3 configured by default, run this:

$ rails –database=sqlite3 myproject

Check out config/database.yml and you’ll see that there are sensible defaults for you there.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK