django 1.8.2
这是我的模特:
class AppUser(AbstractUser):
_SEX = (
('M', 'Male'),
('F', 'Female'),
)
_pregex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
phone = models.CharField(validators=[_pregex], max_length=16, blank=True)
gender = models.CharField(max_length=1, blank=True, choices=_SEX)
birthday = models.DateField(blank=True)
vericode = models.CharField(max_length=40, blank=True) # verification code over SMS?
verified = models.DateTimeField(null=True) # datetime stored when verification happened
@property
def age(self):
today = date.today()
return today.year - self.birthday.year - ((today.month, today.day) < (self.birthday.month, self.birthday.day))
这是我的设置:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# register externals
EXTERNAL_LIBS_PATH = os.path.join(BASE_DIR, "_externals", "libs")
EXTERNAL_APPS_PATH = os.path.join(BASE_DIR, "_externals", "apps")
APPS_PATH = os.path.join(BASE_DIR, "apps")
sys.path = ["", EXTERNAL_APPS_PATH, EXTERNAL_LIBS_PATH, APPS_PATH] + sys.path
# TEST PATH
TEST_ASSETS = os.path.join(BASE_DIR, "_test")
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'suit',
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
'cacheops',
'rest_framework',
'rest_framework.authtoken',
'corsheaders',
'djoser',
'consents'
)
# Custom model for Auth
# AUTH_USER_MODEL = 'consents.AppUser'
我的文件夹结构是
app
-settings.py etc
apps
-consents
在settings.py中,我添加了应用路径: APPS_PATH = os.path.join(BASE_DIR,“apps”)到sys.path,
当我运行python manage.py syncdb(或其他任何东西)时,我得到了这个:
(cmr) F:\_Projects\cmr\containers\backend>python manage.py syncdb
F:\_Projects\cmr\.venv\cmr\lib\importlib\_bootstrap.py:321: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
return f(*args, **kwds)
SystemCheckError: System check identified some issues:
ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'AppUser.groups'.
HINT: Add or change a related_name argument to the definition for 'User.groups' or 'AppUser.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse accessor for 'AppUser.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'AppUser.user_permissions'.
consents.AppUser.groups: (fields.E304) Reverse accessor for 'AppUser.groups' clashes with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition for 'AppUser.groups' or 'User.groups'.
consents.AppUser.user_permissions: (fields.E304) Reverse accessor for 'AppUser.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'AppUser.user_permissions' or 'User.user_permissions'.
如果我在设置中取消注释此行
# AUTH_USER_MODEL = 'consents.AppUser'
我收到另一个错误:
ValueError: Dependency on unknown app: consents
我只需要在默认用户模型中添加几个字段(不希望新创建一个全新的auth类子类分类AbstractBaseUser)
那么我做错了什么?
答案 0 :(得分:1)
<强>溶液强>
然后python manage.py makemigrations工作得很好。