Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 327
Mr. Mouse Mikołaj Avatar asked Aug 01 '16 14:08

Mr. Mouse Mikołaj


2 Answers

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
like image 169
Nyo Man Avatar answered Nov 19 '22 11:11

Nyo Man


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.

like image 2
Thomas Avatar answered Nov 19 '22 10:11

Thomas