django-cms / djangocms-transfer

django CMS Transfer allows you to export and import plugins.
https://www.django-cms.org
Other
19 stars 19 forks source link

Importing content with media fails to due database constraint violations. #18

Open skini-galaxia opened 3 years ago

skini-galaxia commented 3 years ago

Error Logs

django.db.utils.IntegrityError: insert or update on table "bootstrap4_picture_bootstrap4picture" violates foreign key constraint "bootstrap4_picture_b_picture_id_f26d968d_fk_filer_ima"
web_1               | DETAIL:  Key (picture_id)=(6) is not present in table "filer_image".
New
12:56
Internal Server Error: /admin/cms/page/plugin/plugin_importer/import-plugins/
web_1               | Traceback (most recent call last):
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 242, in _commit
web_1               |     return self.connection.commit()
web_1               | psycopg2.errors.ForeignKeyViolation: insert or update on table "bootstrap4_picture_bootstrap4picture" violates foreign key constraint "bootstrap4_picture_b_picture_id_f26d968d_fk_filer_ima"
web_1               | DETAIL:  Key (picture_id)=(6) is not present in table "filer_image".
web_1               |
web_1               |
web_1               | The above exception was the direct cause of the following exception:
web_1               |
web_1               | Traceback (most recent call last):
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
web_1               |     response = get_response(request)
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
web_1               |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1               |   File "/usr/local/lib/python3.8/site-packages/djangocms_transfer/cms_plugins.py", line 147, in import_plugins_view
web_1               |     import_form.run_import()
web_1               |   File "/usr/local/lib/python3.8/site-packages/djangocms_transfer/forms.py", line 159, in run_import
web_1               |     import_plugins(
web_1               |   File "/usr/local/lib/python3.8/contextlib.py", line 75, in inner
web_1               |     return func(*args, **kwds)
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/transaction.py", line 232, in __exit__
web_1               |     connection.commit()
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
web_1               |     return func(*args, **kwargs)
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 266, in commit
web_1               |     self._commit()
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 242, in _commit
web_1               |     return self.connection.commit()
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
web_1               |     raise dj_exc_value.with_traceback(traceback) from exc_value
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 242, in _commit
web_1               |     return self.connection.commit()
web_1               | django.db.utils.IntegrityError: insert or update on table "bootstrap4_picture_bootstrap4picture" violates foreign key constraint "bootstrap4_picture_b_picture_id_f26d968d_fk_filer_ima"
web_1               | DETAIL:  Key (picture_id)=(6) is not present in table "filer_image".
web_1               |
web_1               | [2021-03-18 03:13:08,290] {log.py:224} ERROR - Internal Server Error: /admin/cms/page/plugin/plugin_importer/import-plugins/
web_1               | Traceback (most recent call last):
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 242, in _commit
web_1               |     return self.connection.commit()
web_1               | psycopg2.errors.ForeignKeyViolation: insert or update on table "bootstrap4_picture_bootstrap4picture" violates foreign key constraint "bootstrap4_picture_b_picture_id_f26d968d_fk_filer_ima"
web_1               | DETAIL:  Key (picture_id)=(6) is not present in table "filer_image".
web_1               |
web_1               |
web_1               | The above exception was the direct cause of the following exception:
web_1               |
web_1               | Traceback (most recent call last):
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
web_1               |     response = get_response(request)
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
web_1               |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1               |   File "/usr/local/lib/python3.8/site-packages/djangocms_transfer/cms_plugins.py", line 147, in import_plugins_view
web_1               |     import_form.run_import()
web_1               |   File "/usr/local/lib/python3.8/site-packages/djangocms_transfer/forms.py", line 159, in run_import
web_1               |     import_plugins(
web_1               |   File "/usr/local/lib/python3.8/contextlib.py", line 75, in inner
web_1               |     return func(*args, **kwds)
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/transaction.py", line 232, in __exit__
web_1               |     connection.commit()
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
web_1               |     return func(*args, **kwargs)
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 266, in commit
web_1               |     self._commit()
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 242, in _commit
web_1               |     return self.connection.commit()
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
web_1               |     raise dj_exc_value.with_traceback(traceback) from exc_value
web_1               |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 242, in _commit
web_1               |     return self.connection.commit()
web_1               | django.db.utils.IntegrityError: insert or update on table "bootstrap4_picture_bootstrap4picture" violates foreign key constraint "bootstrap4_picture_b_picture_id_f26d968d_fk_filer_ima"
web_1               | DETAIL:  Key (picture_id)=(6) is not present in table "filer_image".
avryhof commented 3 years ago

The problem is the last sentence in the first paragraph of the readme.

It does not support foreign key relations and won't import/export related data.

I wish there was an option to export the content while simply exporting the foreignkeys as null. That way we could export all of the plugins with their settings, then re-add Django Filer objects. I have a rather large site where I've had to set aside about a week just to rebuild all of the content from the Staging server onto the production server. Being able to export the plugins, re-import them then just upload the images/files anew would save a lot of time.

peacefulseeker commented 2 years ago

+1 to @avryhof' said. Removing media references from the export JSON file would help a lot, eliminating the need of manual editing of the exported JSON file. So with null value for media-related properties the plugins get imported just fine(without media source within the plugin, obviously)

wfehr commented 2 months ago

This might be resolved with the changes from https://github.com/django-cms/djangocms-transfer/pull/20. With now released version 1.0.2 you can define custom serializer handling which also enables custom processing for filer-images, e.g. ignoring them, creating a default image on import or transferring images with base64.