django allauth 添加 uuid 字段

问题描述 投票:0回答:1

我正在尝试为 sigup 添加用户 uuid 字段,但添加后

AUTH_USER_MODEL = "aihuser.UidUser" 

我在 makemigrations 上遇到错误,即使我删除了所有迁移并删除数据库并创建了新数据库:

root@5ce3411a2490:/wg_aihalbum_01# python manage.py makemigrations
Wagtail version is : 4.1.9
DEV environment
hook : register_rich_text_handlers
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.8/site-packages/wagtail_modeltranslation/management/commands/makemigrations_translation.py", line 29, in handle
    super(Command, self).handle(*args, **options)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 96, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/makemigrations.py", line 195, in handle
    autodetector = MigrationAutodetector(
  File "/usr/local/lib/python3.8/site-packages/wagtail_modeltranslation/management/commands/makemigrations_translation.py", line 12, in wrapper
    from_state_page = from_state.apps.get_model('wagtailcore', 'page')
  File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.8/site-packages/django/db/migrations/state.py", line 566, in apps
    return StateApps(self.real_apps, self.models)
  File "/usr/local/lib/python3.8/site-packages/django/db/migrations/state.py", line 637, in __init__
    raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field account.EmailAddress.user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field admin.LogEntry.user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field socialaccount.SocialAccount.user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailcore.Comment.resolved_by was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailcore.Comment.user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailcore.CommentReply.user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailcore.ModelLogEntry.user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailcore.Page.locked_by was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailcore.Page.owner was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailcore.PageLogEntry.user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailcore.PageSubscription.user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailcore.Revision.user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailcore.TaskState.finished_by was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailcore.WorkflowState.requested_by was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtaildocs.Document.uploaded_by_user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtaildocs.UploadedDocument.uploaded_by_user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailimages.Image.uploaded_by_user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailimages.UploadedImage.uploaded_by_user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.
The field wagtailusers.UserProfile.user was declared with a lazy reference to 'aihuser.uiduser', but app 'aihuser' isn't installed.

在我的设置中,我安装的应用程序中有 aihuser :

INSTALLED_APPS = [
    'wagtail_modeltranslation',
    'wagtail_modeltranslation.makemigrations',
    'wagtail_modeltranslation.migrate',

    # default apps
    'apps.home',
    'apps.search',
    'apps.front',
    'apps.site_settings',
    'apps.menus',
    'apps.flex',
    'apps.newsletter',
    'colorfield',
    'wagtail.contrib.forms',
    'wagtail.contrib.redirects',
    'wagtail.contrib.settings',
    'wagtail.embeds',
    'wagtail.sites',
    'wagtail.users',
    'wagtail.snippets',
    'wagtail.documents',
    'wagtail.images',
    'wagtail.search',
    'wagtail.admin',
    'wagtail.locales',
    'wagtail.contrib.routable_page',
    'wagtail.contrib.sitemaps',
    'captcha',
    'wagtailcaptcha',
    'wagtail',
    'modelcluster',
    'taggit',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sitemaps',
    'django.contrib.sites',
    'wagtail.contrib.modeladmin',
    'rest_framework',

    # Authentication
    'allauth',
    'allauth.account',
    'allauth.socialaccount',


    # AIH APPS
    'apps.aihalbum',
    'apps.aihprofile',
    'apps.aihuser',
]

wg_aihalbum_01/apps/aihuser/forms.py

from allauth.account.forms import SignupForm
import uuid

class UidSignupForm(SignupForm):
    def save(self, request):
        user = super().save(request)
        user.user_uid = uuid.uuid4()
        user.save()
        return user

wg_aihalbum_01/apps/aihuser/models.py

from django.contrib.auth.models import AbstractUser
from django.db import models
import uuid

class UidUser(AbstractUser):
    user_uid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)

wg_aihalbum_01/apps/aihuser/apps.py

from django.apps import AppConfig

class AihuserConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'apps.aihuser'
python django wagtail
1个回答
0
投票

您的设置文件用户配置应与自定义用户模型的实际路径匹配,否则 Django 将无法找到它。它当前正在基目录中查找 aihuser 应用程序,根据您在设置文件中声明的应用程序,该应用程序不存在,因为 aihuser 存储在应用程序目录中,因此:

更改此

AUTH_USER_MODEL = "aihuser.UidUser"
以反映用户模型的实际路径,很可能是
AUTH_USER_MODEL = "apps.aihuser.UidUser"

© www.soinside.com 2019 - 2024. All rights reserved.