Having a adding shoe object problem.

Environment:

Request Method: POST
Request URL: http://0.0.0.0:8001/admin/mysite/shoe/add/

Django Version: 5.0.4
Python Version: 3.12.3
Installed Applications:
['corsheaders',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework',
 'mysite']
Installed Middleware:
['corsheaders.middleware.CorsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/db/backends/base/base.py", line 299, in _commit
    return self.connection.commit()
           ^^^^^^^^^^^^^^^^^^^^^^^^

The above exception (FOREIGN KEY constraint failed) was the direct cause of the following exception:
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/contrib/admin/options.py", line 716, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
    result = _process_exception(request, e)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/views/decorators/cache.py", line 80, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/contrib/admin/sites.py", line 240, in inner
    return view(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/contrib/admin/options.py", line 1945, in add_view
    return self.changeform_view(request, None, form_url, extra_context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/utils/decorators.py", line 48, in _wrapper
    return bound_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
    result = _process_exception(request, e)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/contrib/admin/options.py", line 1803, in changeform_view
    with transaction.atomic(using=router.db_for_write(self.model)):
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/db/transaction.py", line 263, in __exit__
    connection.commit()
    ^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/db/backends/base/base.py", line 323, in commit
    self._commit()
    ^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/db/backends/base/base.py", line 298, in _commit
    with debug_transaction(self, "COMMIT"), self.wrap_database_errors:
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mysite/SneakerSite/backend/env/lib/python3.12/site-packages/django/db/backends/base/base.py", line 299, in _commit
    return self.connection.commit()
           ^^^^^^^^^^^^^^^^^^^^^^^^

Exception Type: IntegrityError at /admin/mysite/shoe/add/
Exception Value: FOREIGN KEY constraint failed

my github: GitHub - TNGS0506/SneakerSite

Welcome @shaman22 !

Couple things to mention.

First: When posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted. (I’ve taken the liberty of fixing your original post for you.)

Second: Please don’t expect people to go digging through your github repo to try and identify an error. Copy / paste the code you believe to be relevent here, between the lines of ``` as mentioned above. (In this case, it’s going to be the shoe model along with your ModelAdmin class for it.)

Finally, when posting an error, it’s usually more helpful to copy/paste the error from the console where you’re running runserver than copying the error from the browser.

Directly, this error is generally caused due to not setting a ForeignKey field in the model when trying to save it.

You’re using the admin here, which means that either the foreign key field wasn’t selected when adding the instance, or the ID of the instance doesn’t exist in the related table.