# Rails Tutorial: Create Todo Model

Generate a Todo Model + Migration

Since we will be creating a Todo list application, let us first define the Todo schema:

Todo {
  id: Integer,
  todo: String,
  completed: Boolean
}

To generate the Todo model and it's corresponding database migration run the following command:

$ bin/rails generate model Todo todo:text completed:boolean

You should see an output similar to the following (ignore the Deprecation warning):

   invoke  active_record
   create    db/migrate/20160730043212_create_todos.rb
   create    app/models/todo.rb
   invoke    test_unit
identical      test/models/todo_test.rb
identical      test/fixtures/todos.yml

Now open rails-todolist/app/models/todo.rb and modify the file (changes highlighted):


class Todo < ApplicationRecord
  validates :todo, presence: true
end

In the above Model, we are validating the existence of the todo when we need to create/update a todo item in our table.

Let's now migrate the database:

$ bin/rails db:migrate

You should see an output similar to the following (ignore the Deprecation warning):

== 20160730043212 CreateTodos: migrating ======================================
-- create_table(:todos)
   -> 0.0015s
== 20160730043212 CreateTodos: migrated (0.0016s) =============================