Django – making changes to a model

Unless you get your model/database structure spot on first time, you’ll want to change it. Here is how to keep the database in line with your Django models

  1. Make a change to your model. For instance, in the books app, to the Author class, add an extra field:
    email_address = models.EmailField()
  2. Create the migrations file: python manage.py makemigrations
  3. Run the migrations file: python manage.py migrate

That’s all. Have a look in the admin panel to see the new field

 

You may also like...