Question

Using Django 1.5, trying out the custom user feature.

I only have 3 models in the project. Here they are,

class CustomUser(AbstractBaseUser, PermissionsMixin):
class CustomUserManager(BaseUserManager):
class testModel (models.Model):

No errors when I do python manage.py validate. When I do python manage.py sqlall lancer (lancer is the name of the app), it shows the following,

BEGIN;
CREATE TABLE "lancer_testmodel" (
    "id" serial NOT NULL PRIMARY KEY,
    "first_name" varchar(30) NOT NULL,
    "last_name" varchar(30) NOT NULL
)
;

COMMIT;

What happened to the SQL code for the other two models? Does it only create tables for models that explicitly inherit models.Model?

Additional information,

  1. I added AUTH_USER_MODEL = 'lancer.CustomUser' at the end of my settings.py file per the Django documentation
  2. I commented out all the other installed apps in settings.py. I know that a lot of them were used by contrib.auth, but since I'm using a new custom user model, I just commented everything else out.

This is what it looks like now,

INSTALLED_APPS = (
    #'django.contrib.auth',
    #'django.contrib.contenttypes',
    #'django.contrib.sessions',
    #'django.contrib.sites',
    #'django.contrib.messages',
    #'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'lancer',
)
Was it helpful?

Solution

Well PermissionsMixin depends of

'django.contrib.auth',
'django.contrib.contenttypes',

if you comment only django.contrib.auth and uncomment django.contrib.contenttypes, you will have this error

CommandError: One or more models did not validate: users.myuser: 'groups' has an m2m relation with model <class 'django.contrib.auth.models.Group'>, which has either not been installed or is abstract. users.myuser: 'user_permissions' has an m2m relation with model <class 'django.contrib.auth.models.Permission'>, which has either not been installed or is abstract.

if you uncomment django.contrib.auth and comment django.contrib.contenttypes

You will have this error

CommandError: One or more models did not validate: auth.permission: 'content_type' has a relation with model <class 'django.contrib.contenttypes.models.ContentType'>, which has either not been installed or is abstract.

and if you uncomment the two the sqlall has to generate your table :D

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top