Tutorial by Examples

Django uses migrations to propagate changes you make to your models to your database. Most of the time django can generate them for you. To create a migration, run: $ django-admin makemigrations <app_name> This will create a migration file in the migration submodule of app_name. The first...
Sometimes, migrations generated by Django are not sufficient. This is especially true when you want to make data migrations. For instance, let's you have such model: class Article(models.Model): title = models.CharField(max_length=70) This model already have existing data and now you want ...
When a migration is run, Django stores the name of the migration in a django_migrations table. Create and Fake initial migrations for existing schema If your app already has models and database tables, and doesn’t have migrations. First create initial migrations for you app. python manage.py mak...
Use the makemigrations --name <your_migration_name> option to allow naming the migrations(s) instead of using a generated name. python manage.py makemigrations --name <your_migration_name> <app_name>
Introduction Sometimes migrations conflict, resulting in making the migration unsuccesful. This can happen in a lot of scenerio's, however it can occur on a regular basis when developing one app with a team. Common migration conflicts happen while using source control, especially when the feature-...
First off, let's assume this is your initial model, inside an application called discography: from django.db import models class Album(models.Model): name = models.CharField(max_length=255) artist = models.CharField(max_length=255) Now, you realize that you want to use a ForeignKey ...

Page 1 of 1