0

I'm trying to extend django User model by inheriting AbstractBaseUser so i can be able to manipulate the authentication process of the project.

Here is what my model looks like.

class AccountManager(BaseUserManager):
    ... create_user
    ... create_superuser


class Account(AbstractBaseUser):
    email = models.EmailField(unique=True)
    username = models.CharField(max_length=40, unique=True)

    objects = AccountManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username']

And here is my settings INSTALLED_APPS

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'debug_toolbar',
    'rest_framework',
    'compressor',
    'authentication'
]

AUTH_USER_MODEL = 'authentication.Account'

The problem here i notice the migration process that django is bypassing the auth.0001_initial and it jumped directly creating the admin.0001_initial making my migrations to fail with

django.db.utils.IntegrityError: (1215, u'Cannot add foreign key constraint')

How can i fixed this please help?

1 Answer 1

4

I was able to solve my issue, by this simple steps:

  1. run python manage.py makemigrations authentication - because when using AUTH_USER_MODEL it will replace the migration of auth_user table of django.contrib.auth altering the migration process. Thus if we fail to provide migration file for authentication app migration will no doubt fails.
  2. run python manage.py migrate.

Binggo!

2
  • I get this: No installed app with label 'authentication' Commented Aug 1, 2020 at 12:38
  • 2
    @ReeshabhRanjan 'authentication' is the name of his app. you should use the name of your app instead. python manage.py migrate your_app_name
    – Gomeisa
    Commented Nov 25, 2020 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.