Exercise: Create Migrations

Practice how to create a migration to add a new database table in this challenge.

We'll cover the following

Problem statement

As discussed in this challenge , sometimes an album can be published a number of different times. For example, it might have its original release on CD come out later on vinyl, and finally have a remastered version. We want to add a new table to our music database to store these different releases.

In this challenge, we created a schema to handle our new releases model. We’d like to create a migration that will add the table to the database.

Coding challenge

Complete the code fragment below to create a migration for our new releases table.

It should be named releases and have the following columns:

  • title (string)
  • release_date (date)
  • album_id (which should be a foreign key that refers to the albums table)
  • inserted_at
  • updated_at

It should also have a non-unique index on the :album_id column.

Get hands-on with 1200+ tech skills courses.