Vaibhav
Vaibhav

Reputation: 617

Django makemigrations thrown an error if I add a custom model (Tenant) with app_label='auth'

This is the model that I have

class Tenant(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.TextField(unique=True)

    class Meta:
        app_label = "auth"

When I makemigrations in a new venv or run pytest. I always get an error saying

django.db.migrations.exceptions.NodeNotFoundError: Migration nqm_core.0001_initial dependencies reference nonexistent parent node ('auth', '0013_tenant')

I tried the following ways to resolve this issue

  1. Remove migrations files and re migrate
  2. Fake migrations with zero and then re migrate
  3. Create new database and migrate
  4. Update django and migrate
  5. Create new venv and migrate

None of the above ways worked. The issue got resolved only after I removed the app_label from class Meta for that model. Also I tried removing dependency in the initial migration file but the DB won't migrate at all.

Is this a bug or is there a certain way with which I have to run the migration Currently, I only use the following commands

./manage.py makemigrations
./manage.py migrate

Upvotes: 0

Views: 220

Answers (1)

melnichevv
melnichevv

Reputation: 26

Django has default built-in app with name auth, which handles such models like User, Permission and others.

The easiest solution for you will be to use another app_label

Upvotes: 0

Related Questions