In RoR, after i run the next command for instance:

> rails generate model xyz

And, basically visit for instance 12345_create_xyzs.rb, I'll find something such as this:

def self.up
    create_table :xyzs do |t|

So, after i designed a model, shall we be held really creating a table?

But, where's the database?!

Thanks.

If you use rails generate model zyz, you're telling Rails to create several files for you personally. The file 12345_create_xyzs.rb is exactly what is known as a migration - it consists of the instructions to populate a database using the table structure connected together with your model.

You need to do, however, have to make certain the DB is available (so, for instance in MySql CREATE DATABASE MyDB), as well as your database.yml file has got the correct connection information to that particular database.

If this sounds like true, advertising media are rake db:migrate, the rake task will require proper care of moving your model structure towards the database.

Whenever you rails generate model xyz, you'll be indicating the fields (along with other such things as the database indexes you would like) the table abc may have within the database. The table is representing the model class within the database.

To produce that table within the database, you'd migrate the model definition file (12345_create_xyzs.rb) using rake db:migrate.

The model is symbolized in Rails (i.e. ActiveRecord) code like a class, inside a file known as app/models/xyz.rb:

class Xyz < ActiveRecord::Base
  ...
end

You produce the app/models/xyz.rb file additionally towards the migration file produced above by rails generate model. Within this class is to put such things as indicating associations between models, adding constraints along with other code you'll need.

You need to run the command rake db:migrate to be able to migrate the database. The command rake db:create produces the database...

More details available here.

Additionally, the database should be set up in to the file situated here :

<your_project>/config/database.yml

More details here. More generally, I believe you should browse the "getting started".