Frequently Asked Questions¶
What’s the best way to communicate a problem, question, or suggestion?¶
To submit a feature, to report a bug, or to ask a question, please refer our contributing guidelines.
How can I help?¶
We welcome contributions from the community.
You can help in the following ways:
- Reporting bugs or issues.
- Answering questions which arise on Stack Overflow or as Github issues.
- Providing translations for UI text.
- Suggesting features or changes.
We encourage you to read the contributing guidelines.
key error ‘id’ in
When attempting to import, this error can be seen. This indicates that the
Resource has not been configured
correctly, and the import logic fails. Specifically, the import process is looking for an instance field called
and there is no such field in the import. See Create or update model instances.
How to handle double-save from Signals¶
This issue can apply if you have implemented post-save Signals, and you are using the import workflow in the Admin
interface. You will find that the post-save signal is called twice for each instance. The reason for this is that
save() method is called twice: once for the ‘confirm’ step and once for the ‘import’ step. The call
save() during the ‘confirm’ step is necessary to prove that the object will be saved successfully, or to
report any exceptions in the Admin UI if save failed. After the ‘confirm’ step, the database transaction is rolled
back so that no changes are persisted.
Therefore there is no way at present to stop
save() being called twice, and there will always be two signal calls.
There is a workaround, which is to set a temporary flag on the instance being saved:
class BookResource(resources.ModelResource): def before_save_instance(self, instance, using_transactions, dry_run): # during 'confirm' step, dry_run is True instance.dry_run = dry_run class Meta: model = Book fields = ('id', 'name')
Your signal receiver can then include conditional logic to handle this flag:
@receiver(post_save, sender=Book) def my_callback(sender, **kwargs): instance = kwargs["instance"] if getattr(instance, "dry_run"): # no-op if this is the 'confirm' step return else: # your custom logic here # this will be executed only on the 'import' step pass
How to dynamically set resource values¶
There can be use cases where you need a runtime or user supplied value to be passed to a Resource. See How to dynamically set resource values.
How to set a value on all imported instances prior to persisting¶
If you need to set the same value on each instance created during import then refer to How to set a value on all imported instances prior to persisting.
How to export from more than one table¶
In the usual configuration, a
Resource maps to a single model. If you want to export data associated with
relations to that model, then these values can be defined in the
See Model relations.
How to import imagefield in excel cell¶
Please refer to this issue.
How to hide stack trace in UI error messages¶
Please refer to this issue.
Ids incremented twice during import¶
When importing using the Admin site, it can be that the ids of the imported instances are different from those show in the preview step. This occurs because the rows are imported during ‘confirm’, and then the transaction is rolled back prior to the confirm step. Database implementations mean that sequence numbers may not be reused.
Consider enabling IMPORT_EXPORT_SKIP_ADMIN_CONFIRM as a workaround.
See this issue for more detailed discussion.
Not Null constraint fails when importing blank Charfield¶
See this issue.
Foreign key is null when importing¶
It is possible to reference model relations by defining a field with the double underscore syntax. For example:
fields = ("author__name")
This means that during export, the relation will be followed and the referenced field will be added correctly to the export.
This does not work during import because the reference may not be enough to identify the correct relation instance.
ForeignKeyWidget should be used during import. See the documentation explaining
Foreign Key relations.
How to customize export data¶
See the following responses on StackOverflow:
How to set export file encoding¶
If export produces garbled or unexpected output, you may need to set the export encoding. See this issue.
How to create relation during import if it does not exist¶
How to handle large file uploads¶
If uploading large files, you may encounter time-outs. See Using celery to perform imports and Bulk imports.