Recall & Review
beginner
What command do you use to add a new column to an existing table in Rails?
You create a migration with
rails generate migration AddColumnNameToTableName column_name:data_type and then run rails db:migrate.Click to reveal answer
beginner
How do you remove a column from a table in Rails migrations?
Use
remove_column :table_name, :column_name inside a migration and then run rails db:migrate.Click to reveal answer
beginner
What is the purpose of the
change method in a Rails migration?The
change method defines what changes to make to the database schema. Rails can automatically reverse these changes when rolling back.Click to reveal answer
intermediate
Why should you avoid adding columns directly in the database without migrations in Rails?
Because migrations keep your schema consistent and track changes, making it easier to share and rollback changes safely.
Click to reveal answer
beginner
What data types can you specify when adding a column in Rails migrations?
Common types include
:string, :text, :integer, :boolean, :datetime, and :float.Click to reveal answer
Which Rails command generates a migration to add a column?
✗ Incorrect
The correct syntax is to generate a migration with the name describing the change, like AddAgeToUsers, and specify the column and type.
How do you remove a column named 'email' from the 'customers' table in a migration?
✗ Incorrect
The correct method is remove_column with the table name and column name as arguments.
What happens if you run
rails db:rollback after adding a column with a migration?✗ Incorrect
Rollback reverses the last migration, so the added column will be removed.
Which method inside a migration allows Rails to automatically reverse changes?
✗ Incorrect
The change method lets Rails know how to apply and reverse the migration automatically.
Why is it important to use migrations for schema changes in Rails?
✗ Incorrect
Migrations track changes and allow safe rollbacks, keeping the database schema consistent.
Explain the steps to add a new column to an existing table in Rails using migrations.
Think about how Rails tracks database changes safely.
You got /3 concepts.
Describe how Rails migrations help manage database schema changes like adding or removing columns.
Consider why direct database edits can be risky.
You got /4 concepts.