0

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',
)
niton
  • 8,771
  • 21
  • 32
  • 52
reedvoid
  • 1,203
  • 3
  • 18
  • 34

1 Answers1

4

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

Victor Castillo Torres
  • 10,581
  • 7
  • 40
  • 50
  • Thank you. I actually found 1 more critical thing wrong with my code (which I should have posted in full but it was so long...). Since I copied most of the code from Django's existing contrib.auth.AbstractUser, I also copied this piece of code: `class Meta: verbose_name = _('user') verbose_name_plural = _('users') abstract = True`, which apparently tells Django that this is not a real model or something, since it has this "abstract=True" thing. After removing that, and the changes you suggested, it worked!! Thank you!! – reedvoid Jun 21 '13 at 01:23
  • 1
    Yeah man abstract means ` This model will then not be used to create any database table.` as the doc says (https://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-classes) – Victor Castillo Torres Jun 21 '13 at 01:29
  • This took me so long to figure out! I was trying to add Stormpath to my app and it wasn't mentioned anywhere in their documentation. Thank you! – Rob Carpenter Mar 23 '15 at 16:09