libreosteo / LibreOsteo

Open Source software for osteopathes
GNU General Public License v3.0
30 stars 18 forks source link

Importing archive cause SQL error and in failure #276

Closed jbgury closed 2 years ago

jbgury commented 2 years ago

When trying to reimport an archive on an existing fresh installation, it fails even if the archive is the right version.

Seen behavior In error logs, the following error is displayed : `Traceback (most recent call last): File "C:\Users\jb\Libreosteo\libreosteoweb\api\views.py", line 775, in post File "C:\Users\jb\Libreosteo\venv_64\lib\site-packages\django\core\management__init__.py", line 148, in call_command File "C:\Users\jb\Libreosteo\venv_64\lib\site-packages\django\core\management\base.py", line 364, in execute File "C:\Users\jb\Libreosteo\venv_64\lib\site-packages\django\core\management\commands\flush.py", line 65, in handle django.core.management.base.CommandError: Database C:\Program Files (x86)\Libreosteo\db.sqlite3 couldn't be flushed. Possible reasons:

2022-01-13 21:54:19,602 [ERROR] libreosteoweb.api.views: Import failed Traceback (most recent call last): File "C:\Users\jb\Libreosteo\venv_64\lib\site-packages\django\db\backends\utils.py", line 82, in _execute File "C:\Users\jb\Libreosteo\venv_64\lib\site-packages\django\db\backends\sqlite3\base.py", line 381, in execute sqlite3.IntegrityError: FOREIGN KEY constraint failed`

Analysis

When the flush is performed the following sequence is executed, but dependings of the execution the order is not always the same : BEGIN; DELETE FROM "libreosteoweb_officeevent"; DELETE FROM "libreosteoweb_fileimport"; DELETE FROM "zipcode_lookup_zipcodemapping"; DELETE FROM "django_admin_log"; DELETE FROM "libreosteoweb_document"; DELETE FROM "auth_user"; DELETE FROM "auth_user_user_permissions"; DELETE FROM "django_content_type"; DELETE FROM "libreosteoweb_patientdocument"; DELETE FROM "libreosteoweb_invoice"; DELETE FROM "auth_permission"; DELETE FROM "libreosteoweb_examinationcomment"; DELETE FROM "libreosteoweb_patient"; DELETE FROM "libreosteoweb_therapeutsettings"; DELETE FROM "libreosteoweb_officesettings"; DELETE FROM "libreosteoweb_regulardoctor"; DELETE FROM "auth_group"; DELETE FROM "django_session"; DELETE FROM "libreosteoweb_examination"; DELETE FROM "auth_user_groups"; DELETE FROM "libreosteoweb_paiment_invoice"; DELETE FROM "libreosteoweb_examination_invoices"; DELETE FROM "libreosteoweb_paimentmean"; DELETE FROM "auth_group_permissions"; DELETE FROM "libreosteoweb_paiment"; DELETE FROM "libreosteoweb_loggedinuser"; DELETE FROM "libreosteoweb_children"; COMMIT;

But there is a foreign key on django_content_types to django_admin_log and auth_permission. The delete does not work, flush in failure