Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to specify custom Django Model from nested app as AUTH_USER_MODEL

Tags:

django

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?

like image 482
trubliphone Avatar asked Oct 19 '25 00:10

trubliphone


1 Answers

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'
like image 199
bdoubleu Avatar answered Oct 21 '25 07:10

bdoubleu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!