Search⌘ K
AI Features

Migration File

Explore how to work with Rails migration files to set up and update your database schema. Understand how to enforce essential validations like unique emails and mandatory passwords directly in your database using migration constraints. This lesson guides you through applying these changes and running migrations to ensure your user model is reliable and consistent.

Default migration file

The migration file contained in the db/migrate folder that was generated by rails generate model contains the migration that describes the changes which will be made to the database. This file should look like this:

Ruby
class CreateUsers < ActiveRecord::Migration[6.0]
def change
create_table :users do |t|
t.string :email
t.string :password_digest
t.timestamps
end
end
end

Note: The inserted date at the beginning of the migration file name should be ...