• xadmin.sites.AlreadyRegistered: The model UserProfiles is already registered


    项目中使用了xadmin, 并且我的UserProfiles 继承了django 自带的User,并重写了一些字段

    最后 在xadmin中注册时,我按照下面这样的方式注册:

    xadmin.site.register(UserProfiles, UserProfilesAdmin)
    

      出现了上面的错误:

    Traceback (most recent call last):
      File "D:myblogenvlibsite-packagesdjangoutilsautoreload.py", line 226, in wrapper
        fn(*args, **kwargs)
      File "D:myblogenvlibsite-packagesdjangocoremanagementcommands
    unserver.py", line 109, in inner_run
        autoreload.raise_last_exception()
      File "D:myblogenvlibsite-packagesdjangoutilsautoreload.py", line 249, in raise_last_exception
        six.reraise(*_exception)
      File "D:myblogenvlibsite-packagesdjangoutilssix.py", line 685, in reraise
        raise value.with_traceback(tb)
      File "D:myblogenvlibsite-packagesdjangoutilsautoreload.py", line 226, in wrapper
        fn(*args, **kwargs)
      File "D:myblogenvlibsite-packagesdjango\__init__.py", line 18, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "D:myblogenvlibsite-packagesdjangoapps
    egistry.py", line 115, in populate
        app_config.ready()
      File "D:myblogenvlibsite-packagesxadminapps.py", line 14, in ready
        self.module.autodiscover()
      File "D:myblogenvlibsite-packagesxadmin\__init__.py", line 56, in autodiscover
        import_module('%s.adminx' % app_config.name)
      File "C:Program FilesPython35libimportlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 986, in _gcd_import
      File "<frozen importlib._bootstrap>", line 969, in _find_and_load
      File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 665, in exec_module
      File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
      File "D:MyBlogcuseradminx.py", line 37, in <module>
        xadmin.site.register(UserProfiles, UserProfilesAdmin)
      File "D:myblogenvlibsite-packagesxadminsites.py", line 107, in register
        'The model %s is already registered' % model.__name__)
    xadmin.sites.AlreadyRegistered: The model UserProfiles is already registered
    

      最后解决办法是:

    xadmin.site.unregister(UserProfiles)
    xadmin.site.register(UserProfiles, UserProfilesAdmin)
    

      先注销UserProfiels, 再重新注册.

      然后运行命令:

    makemigrations xadmin
    
    migrate xadmin
    

      

  • 相关阅读:
    Android"寻龙点穴"指南针
    如何获取注册地图API的SHA1值与PackageName?
    如何获取注册地图API的SHA1值与PackageName?
    Error:Execution failed for task ':app:transformClassesWithDexForDebug'解决记录
    Error:Execution failed for task ':app:transformClassesWithDexForDebug'解决记录
    LocationManager的使用
    LocationManager的使用
    Android方向传感器
    Android方向传感器
    Android光线传感器
  • 原文地址:https://www.cnblogs.com/Andy963/p/8573725.html
Copyright © 2020-2023  润新知