Ariejan.net has moved and is now available at https://www.devroom.io

Generate a SQlite-based Rails app

10 October 2006

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.