Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: save() prohibited to prevent data loss due to unsaved related object 'user'. #625

Open
Hamza-Lachi opened this issue Aug 14, 2020 · 1 comment

Comments

@Hamza-Lachi
Copy link

Hi, I want to register me user but I get this error:

Internal Server Error: /api/rest-auth/registration/
Traceback (most recent call last):
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\views\generic\base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\views\decorators\debug.py", line 76, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_auth\registration\views.py", line 46, in dispatch
    return super(RegisterView, self).dispatch(*args, **kwargs)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_framework\views.py", line 505, in dispatch
    response = self.handle_exception(exc)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_framework\views.py", line 465, in handle_exception
    self.raise_uncaught_exception(exc)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_framework\views.py", line 476, in raise_uncaught_exception
    raise exc
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_framework\views.py", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_framework\generics.py", line 190, in post
    return self.create(request, *args, **kwargs)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_auth\registration\views.py", line 65, in create
    user = self.perform_create(serializer)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_auth\registration\views.py", line 73, in perform_create
    user = serializer.save(self.request)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_auth\registration\serializers.py", line 210, in save
    adapter.save_user(request, user, self)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\allauth\account\adapter.py", line 243, in save_user
    user.save()
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\base_user.py", line 66, in save
    super().save(*args, **kwargs)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py", line 
746, in save
    force_update=force_update, update_fields=update_fields)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py", line 
771, in save_base
    update_fields=update_fields,
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\dispatch\dispatcher.py", 
line 175, in send
    for receiver in self._live_receivers(sender)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\dispatch\dispatcher.py", 
line 175, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "D:\Learning\Scripts\practice-course\profilesapi\profiles\models.py", line 29, in create_profile
    Profile.objects.create(user=instance).save()
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py", line 433, in create
    obj.save(force_insert=True, using=self.db)
  File "C:\Users\HamzaLachi\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py", line 
694, in save
    "unsaved related object '%s'." % field.name
ValueError: save() prohibited to prevent data loss due to unsaved related object 'user'.

can you please tell me why I'm getting this issue!

@NoorHasanShaik86
Copy link

any solution for above error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants