DEV Community

Samuel Lubliner
Samuel Lubliner

Posted on • Updated on

ActiveRecord migrations

Models

Ruby classes that generate SQL to CRUD rows in tables

Migrations

Ruby classes that generate SQL to create tables

Rails generator automatically writes most of our migrations. We tell it:

  • the name of the table
  • name of the columns
  • datatypes

Run
rails generate model movie title:string year:integer duration:integer description:text image:string director_id:integer

Two files were created

  • A migration file located in db/migrations
  • A model file containing the schema information located in app/models

Run rake db:migrate

Output will indicate movies table has been created. Verify in /rails/db

Run:

rails generate model director name:string dob:date bio:text image:string

rails generate model actor name:string dob:date bio:text image:string

rails generate model character name:string actor_id:integer movie_id:integer

rake db:migrate executes migrations that haven’t been executed

rake sample_data contains the iMDB Top 250 list

Top comments (0)