# Import Export Models

**URL:** <https://forum.djangoproject.com/t/import-export-models/35021>\
**Category:** Using Django\
**Created:** [September 23, 2024, 6:05am UTC](https://forum.djangoproject.com/t/import-export-models/35021 "2024-09-23T06:05:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luca-marian](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/luca-marian/32/16032_2.png) [@luca-marian](https://forum.djangoproject.com/u/luca-marian)\
**Post date:** [September 23, 2024, 6:05am UTC](https://forum.djangoproject.com/t/import-export-models/35021/1 "2024-09-23T06:05:21Z")

</div>

Hello! I want to create an import/export system in Django. I have multiple instances of the same app, and I want to allow users to add new data from one instance to another using CSV or Excel files. The problem arises when I have models that have a foreign key to another model, and perhaps that object isn’t already in the database. Also, maybe the primary key doesn’t correspond. The flow is as follows: exporting from one instance and importing to another. What do you recommend?

---

<div class="post-metadata">

**Author:** ![anefta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anefta/32/10649_2.png) [@anefta](https://forum.djangoproject.com/u/anefta)\
**Post date:** [September 23, 2024, 7:46am UTC](https://forum.djangoproject.com/t/import-export-models/35021/2 "2024-09-23T07:46:42Z")

</div>

You can use [custom management commands](https://docs.djangoproject.com/en/5.1/howto/custom-management-commands/#module-django.core.management) or standalone python scripts.

---

<div class="post-metadata">

**Author:** ![matthiask](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/matthiask/32/115_2.png) [@matthiask](https://forum.djangoproject.com/u/matthiask)\
**Post date:** [September 23, 2024, 9:01am UTC](https://forum.djangoproject.com/t/import-export-models/35021/3 "2024-09-23T09:01:05Z")

</div>

You could take a look at how [django-import-export · PyPI](https://pypi.org/project/django-import-export/) does it.

---

<div class="post-metadata">

**Author:** ![stribny](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/stribny/32/5592_2.png) [@stribny](https://forum.djangoproject.com/u/stribny)\
**Post date:** [September 23, 2024, 10:39am UTC](https://forum.djangoproject.com/t/import-export-models/35021/4 "2024-09-23T10:39:17Z")

</div>

> [@luca-marian](#):
>
> The problem arises when I have models that have a foreign key to another model, and perhaps that object isn’t already in the database.

I recommend using “natural keys” for identifying which objects are already in the database. Django has a native support for that.
