Complete the code to create a migration that adds a new column.
class AddAgeToUsers < ActiveRecord::Migration[6.0] def change add_column :users, :age, :[1] end end
The add_column method requires the data type of the new column. Here, integer is the correct type for an age.
Complete the code to run all pending migrations.
rails [1]The command rails db:migrate runs all pending migrations to update the database schema.
Fix the error in the migration version declaration.
class CreateProducts < ActiveRecord::Migration[1] def change create_table :products do |t| t.string :name end end end
The migration version must be specified in square brackets, like [6.0], to match the Rails version.
Fill both blanks to define a migration that removes a column.
class RemoveEmailFromUsers < ActiveRecord::Migration[1] def change remove_column :users, :email, :[2] end end
The migration version is specified as [6.1] and the data type of the removed column email is string.
Fill all three blanks to create a migration that renames a column.
class RenameUsernameToLogin < ActiveRecord::Migration[1] def change rename_column :users, :[2], :[3] end end
The migration version is [6.0]. The column username is renamed to login.