Complete the code to generate a new migration file in Rails.
rails generate [1] CreateUsersIn Rails, to create a new migration file, you use rails generate migration.
Complete the migration method to add a new column named 'age' of type integer to the 'users' table.
def change add_column :users, :age, [1] end
The add_column method requires the table name, column name, and the column type. Here, 'age' is an integer.
Fix the error in the migration method to create a 'products' table with a 'name' column of type string.
def change create_table :products do |[1]| [1].string :name end end
The block variable for create_table is conventionally t, used to define columns.
Fill both blanks to write a migration that removes the 'age' column from the 'users' table.
def change [1]_column :users, :age, :[2] end
To remove a column, use remove_column with the table name, column name, and column type.
Fill all three blanks to write a migration that creates a 'posts' table with a 'title' string column and a 'published' boolean column.
def change create_table :posts do |[1]| [1].[2] :title [1].[3] :published end end
The block variable is 't'. Use t.string for 'title' and t.boolean for 'published'.