2

I am unable to specify a custom AUTH_USER_MODEL if that model is in a nested application.

Here is some project structure:

├── project
│   ├── settings.py
│   ├── my_parent_app
│   │   ├── __init__.py
│   │   ├── apps.py
│   │   └── my_child_app
│   │       ├── __init__.py
│   │       ├── apps.py
│   │       └── models.py

and here is some code:

project/my_parent_app/my_child_app/models.py:

from django.contrib.auth.models import AbstractUser
from django.db import models

class User(AbstractUser):
  is_a_nice_user = models.BooleanField(default=False)

project/settings.py:

INSTALLED_APPS = [
  'my_parent_app',
  'my_parent_app.my_child_app',
]  
AUTH_USER_MODEL = 'my_parent_app.my_child_app.User'

When I try to do anything, I get this error:

ValueError: Invalid model reference 'my_parent_app.my_child_app.User'. String model references must be of the form 'app_label.ModelName'.

This is a very similar to this question. But how can I solve this without resorting to making my_child_app a separate top-level app?

trubliphone
  • 4,132
  • 3
  • 42
  • 66

1 Answers1

6

AUTH_USER_MODEL has to be in the format app_label.model_name

INSTALLED_APPS = [
    'my_parent_app',
    'my_parent_app.my_child_app',
]  
AUTH_USER_MODEL = 'my_child_app.User'
bdoubleu
  • 5,568
  • 2
  • 20
  • 53
  • Thanks. That works. The reason this _hadn't_ been working was that `my_child_app` was actually called `users` which, presumably, conflicted w/ an existing Django app_label. – trubliphone Aug 15 '19 at 13:07