1

I am working with a custom build user model in Django and there was some message in the terminal at the time of migrate given in the stackoverflow link.

However, I have failed to solve that and it didn't hamper to run the project, so I actually ignore it and continue with my code. Now when I try to log-in to the admin panel(http://127.0.0.1:8000/admin/) it shows the following error:

Internal Server Error: /admin/login/
Traceback (most recent call last):
  File "G:\Python\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "G:\Python\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "G:\Python\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "G:\Python\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "G:\Python\lib\site-packages\django\contrib\admin\sites.py", line 407, in login
    return LoginView.as_view(**defaults)(request)
  File "G:\Python\lib\site-packages\django\views\generic\base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "G:\Python\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "G:\Python\lib\site-packages\django\views\decorators\debug.py", line 76, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
  File "G:\Python\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "G:\Python\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "G:\Python\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "G:\Python\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "G:\Python\lib\site-packages\django\contrib\auth\views.py", line 63, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "G:\Python\lib\site-packages\django\views\generic\base.py", line 97, in dispatch
    return handler(request, *args, **kwargs)
  File "G:\Python\lib\site-packages\django\views\generic\edit.py", line 142, in post
    return self.form_valid(form)
  File "G:\Python\lib\site-packages\django\contrib\auth\views.py", line 92, in form_valid
    auth_login(self.request, form.get_user())
  File "G:\Python\lib\site-packages\django\contrib\auth\__init__.py", line 131, in login
    user_logged_in.send(sender=user.__class__, request=request, user=user)
  File "G:\Python\lib\site-packages\django\dispatch\dispatcher.py", line 173, in send
    return [
  File "G:\Python\lib\site-packages\django\dispatch\dispatcher.py", line 174, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "G:\Python\lib\site-packages\django\contrib\auth\models.py", line 20, in update_last_login
    user.save(update_fields=['last_login'])
  File "G:\Python\lib\site-packages\django\contrib\auth\base_user.py", line 66, in save
    super().save(*args, **kwargs)
  File "G:\Python\lib\site-packages\django\db\models\base.py", line 745, in save
    self.save_base(using=using, force_insert=force_insert,
  File "G:\Python\lib\site-packages\django\db\models\base.py", line 782, in save_base
    updated = self._save_table(
  File "G:\Python\lib\site-packages\django\db\models\base.py", line 847, in _save_table
    raise ValueError("Cannot force an update in save() with no primary key.")
ValueError: Cannot force an update in save() with no primary key.
Kanchon Gharami
  • 777
  • 1
  • 11
  • 30

1 Answers1

0

I was facing the same issue,I searched everywhere. I found the answer in the link I will attach below.

1-to change the database name. 2-makemigrations and migrate.

but it failed to work until I read towen's comment! I was always creating the super user before migrating, which is wrong!

you have make the migrations before creating the super user. so

python manage.py makemigrations 

then

python manage.py migrate

then all the tables are ready to work properly, now we can create the super user, and it will have the primary key and it will work

python manage.py createsuperuser 

https://github.com/nesdis/djongo/issues/3

Sara Sherif
  • 68
  • 1
  • 7