[Django] What to do if an Integrity Error occurs when registering data from the management site to the database

environment

background

While studying in Django's Primer, I got the following error in the section Creating data from the admin site to the database:

IntegrityError at /admin/diary/diary/add/ ������������"django_admin_log"������������������������������������������"django_admin_log_user_id_c564eba6_fk_auth_user_id"������������������������ DETAIL: ������������"auth_user"���������(user_id)=(3)������������������ Request Method: POST Request URL: http://127.0.0.1:8000/admin/diary/diary/add/ Django Version: 2.2.2 Exception Type: IntegrityError Exception Value: ������������"django_admin_log"������������������������������������������"django_admin_log_user_id_c564eba6_fk_auth_user_id"������������������������ DETAIL: ������������"auth_user"���������(user_id)=(3)������������������ Exception Location: C:\Users\grin\Anaconda3\envs\django\lib\site-packages\django\db\backends\base\base.py in _commit, line 240 Python Executable: C:\Users\grin\Anaconda3\envs\django\python.exe Python Version: 3.7.3

It looks like a django_admin_log integrity error.

It seems to occur when the django_admin_log table contains a foreign key relationship with the old auth_user table. So you need to drop it and recreate the table.

approach

$ python manage.py dbshell DROP TABLE django_admin_log; \q $ python manage.py sqlmigrate admin 0001 | python manage.py dbshell

References / URL

Recommended Posts

[Django] What to do if an Integrity Error occurs when registering data from the management site to the database
What to do when an error occurs with import _ssl
[Beanstalk] What to do when an error occurs with import uuid
What to do if you get an error when trying to load mnist
What to do if you get an error when installing Dlib (Ubuntu)
[OSX] [pyenv] What to do when an SSL error occurs in pip
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
[python] What to do when an error occurs in send_keys of headless chrome
What to do if Django can't load an image from a static folder
What to do if you get an error when installing python with pyenv
What to do if a version error occurs in the selenium Chrome driver
What to do if an SSL connection error (ssl.SSLError: [SSL: DH_KEY_TOO_SMALL]) occurs on Ubuntu 20.04
What to do if an error occurs when loading a python project created with poetry into VS Code
[Python] Type Error:'WebElement' object is not iterable What to do when an error occurs
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get a memory error when converting from PySparkDataFrame to PandasDataFrame
What to do if the print command itself causes an error in Maya python
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if you get an Import Error when importing matplotlib with Jupyter
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
What to do when a Remove Error occurs when updating conda
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do if a communication error occurs due to proxy when installing with package management of pip, npm, gem
What to do if you get an error when running "certbot renew" in CakePHP environment
What to do if you get an Undefined error when trying to use pip with pyenv
What to do when you get "I can't see the site !!!!"
I built an environment from centos installation to php source expansion on linux, but what to do when a browser error occurs
What to do if pyenv install does not proceed with an error
[Python] What to do when an error related to SSL authentication is returned
What to do if fprintd requires a password when registering your fingerprint
What to do when psycopg2 throws an error when pipenv lock under Pipenv environment
What to do if an error occurs in TensorFlow RNN related import or RNN (LSTM) Cell (v 0.11r ~)
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
[Python] I want to know the variables in the function when an error occurs!
What to do if CERTIFICATE_VERIFY_FAILED occurs when nltk.download () is done on macOS pyhon
What to do if a Unicode Encode Error occurs in Sublime Text Python
What to do when PermissionError of tempfile.mkstemp occurs
A convenient function memo to use when you want to enter the debugger if an error occurs when running a Python script.
What to do if you get the error "Error: opencv3: Does not support building both Python 2 and 3 wrappers" when installing openCV 3
What to do if Python does not switch from the System version in pyenv
What to do if you run python in IntelliJ and end with an error
What to do if a UnicodeDecodeError occurs in pip
What to do if you get an error when vagrant up when you enable public_network or private_network on Vagrant + Arch Linux → Install netctl
What to do when you get an error saying "Name resolution temporarily failed" on linux
What to do if ʻObject arrays cannot be loaded when allow_pickle = False` occurs in numpy.load ()
What to do if the package dependency cannot be repaired
How to do the initial setup from Django project creation
What to do if package installation fails when deploying to heroku
What to do when "Invalid HTTP_HOST header" appears in Django
DJango Memo: From the beginning (more edits to the management screen)
What to do if you get `locale.Error: unsupported locale setting` when getting the day of the week from a date in Python
[Django] What to do if the model you want to create has a large number of fields
What to do if you get a must override `get_config` error when trying to model.save in Keras
What to do if pip --user returns an error in a virtual environment created with pyenv
[AWS] What to do when the ping command causes a "timeout"
What to do when the jupyterlab extension settings are not reflected
What to do if Insecure Platform Warning appears when running Python
What to do if the inode is exhausted on EC2 Linux
What to do if you can't use the trash in Lubuntu 18.04.
What to do when UnicodeDecodeError occurs during read_csv in pandas (pd.read_table ())
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python