Skip to main content

Generate a SQlite-based Rails app

·187 words·1 min· ·
General Everything RubyOnRails Databases SQlite Features
Ariejan de Vroom
Author
Ariejan de Vroom
Jack of all Trades, Professional Software Craftsman

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.

Related

Easily create a FavIcon online!
·124 words·1 min
General Everything Blog Web Development Links Personal
Hi-Res Wallpapers for your MacBook!
·44 words·1 min
General Everything Blog Links Eye Candy MacBook Professional
Top 5 DVDs you must have
·563 words·3 mins
General Everything Blog Lists Movies DVD Coding