Exercise: Create Schemas in Ecto

Practice how to create an Ecto schema from scratch in this challenge.

We'll cover the following

Problem statement

Sometimes, an album can be published several different times. For example, it might have its original release on CD, later come out on vinyl, and later have a remastered version. We want to add a new table to our music database to store these different releases.

The table will be called releases and will have the following columns:

  • id (primary key)
  • title (string)
  • release_date (date)
  • format (string)

We also want a has_many relationship between albums and releases, and a reciprocal belongs_to relationship between releases and albums.

Code challenge

Use Ecto’s schema API to create a schema for the releases table. It should have the correct data types for each column and define the correct association with albums.

Get hands-on with 1400+ tech skills courses.