django 1.5.1
I create custom auth model:
file api/models.py
from django.contrib.auth.models import BaseUserManager, AbstractUser
class User(AbstractUser):
token = models.CharField(max_length=64, null=False, blank=False, help_text=_('Photo for carte'), unique=True)
updated_token = models.DateTimeField(auto_now_add=True, help_text=_('Create record'))
USERNAME_FIELD = 'email'
objects = MyUserManager()
def __unicode__(self):
return "пользователь: %s" % self.email
class Meta:
app_label = 'custom_auth'
file settings.py
AUTH_USER_MODEL = 'custom_auth.User'
.....
INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api',
.....
'south',
'django.contrib.admin',
)
on ./manage.py syncdb I get an error:
admin.logentry: 'user' has a relation with model <class 'api.models.User'>, which has either not been installed or is abstract.
How decide this problem?
Edit 1 tried comment line and make syncdb:
'django.contrib.admin',
syncdb was successful after that tried create user in ./manage.py shell
In [1]: from api.models import User
In [2]: User.objects.create_superuser('[email protected]', 'test')
and recieve error:
DatabaseError: (1146, "Table 'app_name.custom_auth_user' doesn't exist")
You will need to set an app_label
on your class which is also in your INSTALLED_APPS
: either set app_label = 'api'
(the default), or add 'custom_auth'
to your INSTALLED_APPS
(of course, it needs to be a valid app then).
The validation process in Django tries to get the new User class using get_model
, and by default get_model
returns models for installed apps only. You can verify with your current code:
>>> loading.get_model('custom_auth', 'user')
>>> loading.get_model('custom_auth', 'user', only_installed=False)
> api.models.User
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With