Thursday, June 25, 2015

Re: ValueError: Dependency on unknown app

Have you tried cw_auth.models.AppUser as the value for AUTH_USER_MODEL?

-James

On Jun 25, 2015 12:45 PM, "MamEshe5minPlz" <dmitriy.zhura@gmail.com> wrote:
I'm trying to use custom User model. Created app named "cw_auth", created "AppUser" model in it, added module to INSTALLED_APPS and added 
AUTH_USER_MODEL = 'cw_auth.AppUser'
to settings.py file. But when I'm trying to perform
./manage.py makemigrations cw_auth
I'm getting errors
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "c:\Python34\lib\site-packages\django\core\management\__init__.py", line
338, in execute_from_command_line
    utility.execute()
  File "c:\Python34\lib\site-packages\django\core\management\__init__.py", line
330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "c:\Python34\lib\site-packages\django\core\management\base.py", line 390,
 in run_from_argv
    self.execute(*args, **cmd_options)
  File "c:\Python34\lib\site-packages\django\core\management\base.py", line 441,
 in execute
    output = self.handle(*args, **options)
  File "c:\Python34\lib\site-packages\django\core\management\commands\makemigrat
ions.py", line 63, in handle
    loader = MigrationLoader(None, ignore_no_migrations=True)
  File "c:\Python34\lib\site-packages\django\db\migrations\loader.py", line 47,
in __init__
    self.build_graph()
  File "c:\Python34\lib\site-packages\django\db\migrations\loader.py", line 287,
 in build_graph
    parent = self.check_key(parent, key[0])
  File "c:\Python34\lib\site-packages\django\db\migrations\loader.py", line 165,
 in check_key
    raise ValueError("Dependency on unknown app: %s" % key[0])
ValueError: Dependency on unknown app: cw_auth

cw_auth/models.py code bellow:
from django.db import models
from django.contrib.auth.models import (
BaseUserManager, AbstractBaseUser
)


class AppUserManager(BaseUserManager):
def create_user(self, email, first_name, last_name, role=3, password=None):
"""
Creates and saves a User
"""
if not email:
raise ValueError('Users must have an email address')

user = self.model(
email=self.normalize_email(email),
first_name=first_name,
last_name=last_name,
role=role,
)

user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, email, first_name, last_name, password):
"""
Creates and saves a superuser
"""
user = self.create_user(email,
first_name=first_name,
last_name=last_name,
role=1,
password=password
)
return user


class AppUser(AbstractBaseUser):
ROLES = ((1, 'Administrator'),
(2, 'Manager'),
(3, 'Customer'),
(4, 'Provider'))
role = models.IntegerField(choices=ROLES, db_index=True)
bonus_coins = models.DecimalField(max_digits=9, decimal_places=3)
balance = models.DecimalField(max_digits=12,decimal_places=2)
consumables = models.IntegerField() # amount of available bids for providers
avatar = models.ImageField(max_length=250)
rating = models.DecimalField(max_digits=4,decimal_places=2)
company_name = models.TextField(max_length=100, blank=True)
birth_date = models.DateField()

email = models.EmailField(verbose_name='email address', max_length=255, unique=True)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
is_active = models.BooleanField(default=False)
date_joined = models.DateTimeField(auto_now_add=True)

objects = AppUserManager()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name']

def get_full_name(self):
return ' '.join([self.first_name, self.last_name])

def get_short_name(self):
return self.first_name

def __str__(self):
return self.get_full_name()

def has_perm(self, perm, obj=None):
"""Does the user have a specific permission?"""
# Simplest possible answer: Yes, always
return True

def has_module_perms(self, app_label):
"""Does the user have permissions to view the app `app_label`?"""
# Simplest possible answer: Yes, always
return True

@property
def is_staff(self):
"""Is the user a member of staff?"""
# If role is admin or manager
return self.role == 1 or self.role == 2

Without AUTH_USER_MODEL migrations going well. Please help.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6bc750f3-2774-407a-9827-978e739fe0f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciV%3DpNU4zMpQLJdcQ%2BAKfuWPyA-BSNAP5vqr3%3DSSBiaxag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment