Complete the code to add a new column named age of type integer to the users table.
class AddAgeToUsers < ActiveRecord::Migration[6.1] def change add_column :users, :age, :[1] end end
The add_column method requires the table name, column name, and the column type. Here, integer is the correct type for the age column.
Complete the code to remove the email column from the customers table.
class RemoveEmailFromCustomers < ActiveRecord::Migration[6.1] def change remove_column :customers, :[1] end end
The remove_column method needs the table name and the column name to remove. Here, the column to remove is email.
Fix the error in the migration code to add a published_at column of type datetime to the posts table.
class AddPublishedAtToPosts < ActiveRecord::Migration[6.1] def change add_column :posts, :published_at, :[1] end end
string instead of datetime.integer or boolean incorrectly.The published_at column should store date and time, so the correct type is datetime.
Fill both blanks to add a price column of type decimal with precision 8 and scale 2 to the products table.
class AddPriceToProducts < ActiveRecord::Migration[6.1] def change add_column :products, :price, :[1], precision: [2], scale: 2 end end
integer instead of decimal.The price column should be decimal type with precision 8 and scale 2 to store prices accurately.
Fill all three blanks to create a migration that removes the description column of type text from the items table.
class RemoveDescriptionFromItems < ActiveRecord::Migration[6.1] def change remove_column :items, :[1], :[2], null: [3] end end
To remove the description column of type text, specify the column name, type, and null: false if the column was not nullable.