pennersr / django-allauth

Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
https://allauth.org
MIT License
9.55k stars 3.03k forks source link

Conflicting 'user_groups' models in application #1189

Closed gerbyzation closed 9 years ago

gerbyzation commented 9 years ago

Hi,

I want to implement a custom signup form, but when doing so I run into RuntimeError: Conflicting 'user_groups' models in application 'accounts': <class 'accounts.models.User_groups'> and <class 'apps.accounts.models.User_groups'>.. I'm using a custom user model and user profile, but should all be fairly straight forward, so I'm not sure what's causing the issue here?

Thanks!

# Form
class SignUpForm(forms.Form):

    TITLE_CHOICES = [
        ('Mr', 'Mr.',),
        ('Ms', 'Ms.',),
        ('Mrs', 'Mrs.',),
        ('Dr', 'Dr.',),
        ('Prof', 'Prof.',)
    ]

    title = forms.ChoiceField(choices=TITLE_CHOICES)
    first_name = forms.CharField(max_length=255)
    last_name = forms.CharField(max_length=255)
    role = forms.CharField(max_length=100)
    company = forms.CharField(max_length=100)
    country = forms.ChoiceField(choices=COUNTRY_CHOICES)
    phone = forms.CharField(max_length=15)
    reference = forms.CharField(max_length=100)

    class Meta:
        fields = [
            'first_name', 'last_name',
            'title', 'role',
            'company', 'country', 'phone', 'reference'
        ]
        widgets = {
            'first_name': forms.TextInput(attrs={
                'placeholder': 'First Name',
            }),
            'last_name': forms.TextInput(attrs={
                'placeholder': 'Last Name',
            }),
        }

    def signup(self, request, user):
        user.first_name = self.cleaned_data['first_name']
        user.last_name = self.cleaned_data['last_name']
        user.save()
        UserProfile.objects.create(
            user=user,
            title=self.cleaned_data['title'],
            role=self.cleaned_data['role'],
            company=self.cleaned_data['company'],
            country=self.cleaned_data['country'],
            phone=self.cleaned_data['phone'],
            reference=self.cleaned_data['reference']
        )

# user profile
class UserProfile(models.Model):

    user = models.OneToOneField(settings.AUTH_USER_MODEL)
    title = models.CharField(max_length=10)
    role = models.CharField(max_length=100)
    company = models.CharField(max_length=100)
    country = models.CharField(max_length=2, choices=COUNTRY_CHOICES)
    phone = models.CharField(max_length=15)
    reference = models.CharField(max_length=100)

# User
class User(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(unique=True)

    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)

    date_joined = models.DateTimeField(auto_now_add=True)
    is_active = models.BooleanField(default=True)

    braintree_id = models.CharField(max_length=50)

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

    is_staff = models.BooleanField(default=False)

    objects = UserManager()

The full traceback:

/Users/gerritneven/Projects/criticalhit_mobile/playerxp/apps/accounts/models.py:36: RemovedInDjango19Warning: Model class apps.accounts.models.User doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
  class User(AbstractBaseUser, PermissionsMixin):

/Users/gerritneven/Projects/criticalhit_mobile/playerxp/apps/accounts/models.py:36: RemovedInDjango19Warning: Model class apps.accounts.models.User doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
  class User(AbstractBaseUser, PermissionsMixin):

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10a5e0a60>
Traceback (most recent call last):
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/core/urlresolvers.py", line 393, in urlconf_module
    return self._urlconf_module
AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/utils/autoreload.py", line 229, in wrapper
    fn(*args, **kwargs)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
    autoreload.raise_last_exception()
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/utils/autoreload.py", line 252, in raise_last_exception
    six.reraise(*_exception)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/utils/six.py", line 658, in reraise
    raise value.with_traceback(tb)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/utils/autoreload.py", line 229, in wrapper
    fn(*args, **kwargs)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/debug_toolbar/apps.py", line 15, in ready
    dt_settings.patch_all()
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/debug_toolbar/settings.py", line 228, in patch_all
    patch_root_urlconf()
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/debug_toolbar/settings.py", line 216, in patch_root_urlconf
    reverse('djdt:render_panel')
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/core/urlresolvers.py", line 549, in reverse
    app_list = resolver.app_dict[ns]
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/core/urlresolvers.py", line 351, in app_dict
    self._populate()
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/core/urlresolvers.py", line 284, in _populate
    for pattern in reversed(self.url_patterns):
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/core/urlresolvers.py", line 401, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/core/urlresolvers.py", line 395, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/importlib/__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 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/gerritneven/Projects/criticalhit_mobile/playerxp/config/urls.py", line 27, in <module>
    url(r'^accounts/', include('allauth.urls')),
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/conf/urls/__init__.py", line 33, in include
    urlconf_module = import_module(urlconf_module)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/importlib/__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 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/allauth/urls.py", line 8, in <module>
    urlpatterns = [url('^', include('allauth.account.urls'))]
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/conf/urls/__init__.py", line 33, in include
    urlconf_module = import_module(urlconf_module)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/importlib/__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 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/allauth/account/urls.py", line 4, in <module>
    from . import views
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/allauth/account/views.py", line 19, in <module>
    from .forms import (
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/allauth/account/forms.py", line 206, in <module>
    class BaseSignupForm(_base_signup_form_class()):
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/allauth/account/forms.py", line 185, in _base_signup_form_class
    mod = import_module(fc_module)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/Users/gerritneven/Projects/criticalhit_mobile/playerxp/apps/accounts/forms.py", line 4, in <module>
    from .models import UserProfile
  File "/Users/gerritneven/Projects/criticalhit_mobile/playerxp/apps/accounts/models.py", line 36, in <module>
    class User(AbstractBaseUser, PermissionsMixin):
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/db/models/base.py", line 276, in __new__
    new_class.add_to_class(field.name, new_field)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/db/models/base.py", line 324, in add_to_class
    value.contribute_to_class(cls, name)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/db/models/fields/related.py", line 2549, in contribute_to_class
    self.rel.through = create_many_to_many_intermediary_model(self, cls)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/db/models/fields/related.py", line 2106, in create_many_to_many_intermediary_model
    db_constraint=field.rel.db_constraint,
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/db/models/base.py", line 309, in __new__
    new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/apps/registry.py", line 221, in register_model
    (model_name, app_label, app_models[model_name], model))
RuntimeError: Conflicting 'user_groups' models in application 'accounts': <class 'accounts.models.User_groups'> and <class 'apps.accounts.models.User_groups'>.
pennersr commented 9 years ago

This has little relation to allauth, it does not feature an accounts app...

gerbyzation commented 9 years ago

Sorry if I'm being ignorant, but to me it seems it does? That the accounts app is not part of allauth is correct, but there needs to be some app where I define the custom signup form. This error is the direct result of specifying a custom signup form for allauth in settings ( ACCOUNT_SIGNUP_FORM_CLASS = 'apps.accounts.forms.SignUpForm'), which gives me the impression this has quite a lot to do with allauth. If I'm wrong; please enlighten me

pennersr commented 9 years ago

What I meant was that allauth is not the cause here, there is not an issue I can fix. It is not feasible for me to support tracking down project specific issues, therefore I have to close them. What I would do to track this down is start out at the root issue, which does not seem to be the conflicting models exception, but this one:

Unhandled exception in thread started by .wrapper at 0x10a5e0a60>
Traceback (most recent call last):
  File "/Users/gerritneven/.virtualenvs/playerxp-dev/lib/python3.5/site-packages/django/core/urlresolvers.py", line 393, in urlconf_module
    return self._urlconf_module
AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'
During handling of the above exception, another exception occurred:
gerbyzation commented 9 years ago

Alright, thanks. Due to the errors I was under the impression it was at least related to allauth, but after digging around for a while I finally discovered it doesn't like the relative import of the profile model somehow, absolute import solved it. My bad, and thank you!