Complete the code to add a string column named 'title' to the 'books' table.
add_column :books, :title, :[1]The string type is used for short text columns like titles.
Complete the code to create a 'published' boolean column with a default value of false.
add_column :books, :published, :boolean, default: [1]The default value for a boolean column should be false to indicate unpublished by default.
Fix the error in the migration to add a 'price' column with decimal type and precision 8, scale 2.
add_column :products, :price, :[1], precision: 8, scale: 2
The decimal type is used for precise numbers like prices, with specified precision and scale.
Fill both blanks to add a 'username' column that cannot be null and has a unique index.
add_column :users, :username, :[1], null: [2] add_index :users, :username, unique: true
The username should be a string and cannot be null, so null: false is used.
Fill all three blanks to create a 'created_at' timestamp column that cannot be null and has a default of current time.
add_column :orders, :created_at, :[1], null: [2], default: [3]
Timestamps use datetime. It should not be null, and default is set to current time using a lambda.