Search⌘ K
AI Features

Create Schemas

Explore how to create schemas using Ecto to map Elixir structs to database tables effectively. Learn to define fields with proper data types, handle default primary key behavior, and use timestamps for automatic record tracking.

Let’s look at the DSL Ecto provides to create schemas. We’ll use the DSL to specify the fields we want to map and their data types.

Map schema fields

Let’s start with our tracks table. We’ll have just five fields for now:

  • id, a unique ID for our track.

  • title, a string representing the track’s title.

  • duration, the length of the track in seconds. ...