DEV Community

Samuel Lubliner
Samuel Lubliner

Posted on • Edited 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

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay