Custom user model with Django CMS. Cannot resolve bases for cms.PageUser
Asked Answered
A

2

7

I'm trying to use custom user model with Django CMS. I created new users app with this model:

users.models:

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


class User(AbstractUser):
    bio = models.TextField(max_length=500, blank=True)
    location = models.CharField(max_length=30, blank=True)
    birth_date = models.DateField(null=True, blank=True)

Here project settings:

settings:

INSTALLED_APPS = [
    'djangocms_admin_style',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.admin',
    'django.contrib.sites',
    'django.contrib.sitemaps',
    'django.contrib.staticfiles',
    'django.contrib.messages',
    'users',
    'cms',
    'menus',
    ...
]

AUTH_USER_MODEL = 'users.User'

Why I have this error?

manage.py makemigrations users

django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'cms.PageUser'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
 in an app with no migrations; see https://docs.djangoproject.com/en/1.8/topics/migrations/#dependencies for more
Androsphinx answered 1/8, 2016 at 14:15 Comment(2)
Have you done manage.py makemigrations <app_label>?Pour
It might be worth starting again with a fresh blank database and try going a migrate first, then do a makemigration.Martyrdom
T
8

I ran into same problem and I followed your instruction but on step 9 I encounter this error: django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency users.0001_initial on database 'default'.

I got it to work by reordering your step (without commenting out the AUTH_USER_MODEL and without commenting out users from installed apps)

  1. Removed migrations folder from users app
  2. Started with a blank database
  3. Ran manage.py makemigrations users
  4. Ran manage.py migrate
  5. Ran manage.py makemigrations
  6. Ran manage.py migrate
Tyndareus answered 6/7, 2019 at 23:31 Comment(0)
S
2

I ran into the same issue. Based on a reply to https://github.com/divio/django-cms/issues/3436 I did the following which worked for me:

  1. Removed migrations folder from users app
  2. Commented out users from installed apps
  3. Commented out the AUTH_USER_MODEL bit
  4. Started with a blank database
  5. Ran manage.py makemigrations
  6. Ran manage.py migrate
  7. Put back the things, I commented out previously.
  8. Ran manage.py makemigrations users
  9. Ran manage.py migrate

I know it's an old post but it might help others.

Singlecross answered 18/2, 2018 at 17:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.