# Bulk import from another database to a Django powered one

**URL:** <https://forum.djangoproject.com/t/bulk-import-from-another-database-to-a-django-powered-one/19837>\
**Category:** Using the ORM\
**Created:** [March 28, 2023, 4:25am UTC](https://forum.djangoproject.com/t/bulk-import-from-another-database-to-a-django-powered-one/19837 "2023-03-28T04:25:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anjanesh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anjanesh/32/4583_2.png) [@anjanesh](https://forum.djangoproject.com/u/anjanesh)\
**Post date:** [March 28, 2023, 4:25am UTC](https://forum.djangoproject.com/t/bulk-import-from-another-database-to-a-django-powered-one/19837/1 "2023-03-28T04:25:22Z")

</div>

I have created the models for a new Django app which Im re-writing from a app written in CodeIgniter 3.

Let’s say I wanted to migrate the customers table from CI to Django - is it safe to write a separate script to query the CI database and output raw SQL insert statements which I’ll run on the new database ?

Is it safe ? Or do I have to output something like to execute in shell ?

```auto
Customer.objects.bulk_create([
... Customer(name='John'),
... Customer(name='Mary'),
])

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 28, 2023, 10:59am UTC](https://forum.djangoproject.com/t/bulk-import-from-another-database-to-a-django-powered-one/19837/2 "2023-03-28T10:59:00Z")

</div>

> [@anjanesh](#):
>
> Is it safe ?

What makes you think that it might not be safe? (What are you concerned about?)

---

<div class="post-metadata">

**Author:** ![anjanesh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anjanesh/32/4583_2.png) [@anjanesh](https://forum.djangoproject.com/u/anjanesh)\
**Post date:** [March 28, 2023, 11:24am UTC](https://forum.djangoproject.com/t/bulk-import-from-another-database-to-a-django-powered-one/19837/3 "2023-03-28T11:24:34Z")

</div>

I meant, if running raw SQL statements safe ? Or is running `bulk_create` safer ?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 28, 2023, 11:40am UTC](https://forum.djangoproject.com/t/bulk-import-from-another-database-to-a-django-powered-one/19837/4 "2023-03-28T11:40:00Z")

</div>

Unfortunately, “safe” is a vague term and is not an absolute quantity.

To try and rephrase, what is the root issue or concern behind this question? What do you mean by “safe” in this context? (What are you thinking might happen?)

---

<div class="post-metadata">

**Author:** ![anjanesh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anjanesh/32/4583_2.png) [@anjanesh](https://forum.djangoproject.com/u/anjanesh)\
**Post date:** [March 28, 2023, 12:19pm UTC](https://forum.djangoproject.com/t/bulk-import-from-another-database-to-a-django-powered-one/19837/5 "2023-03-28T12:19:56Z")

</div>

I thought if data is entered via ORM via shell or otherwise the data would be inserted post validation. On the other hand, via raw SQL, its just a dump of rows.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 28, 2023, 12:39pm UTC](https://forum.djangoproject.com/t/bulk-import-from-another-database-to-a-django-powered-one/19837/6 "2023-03-28T12:39:18Z")

</div>

> [@anjanesh](#):
>
> ORM via shell or otherwise the data would be inserted post validation.

That is not an accurate assumption. The `bulk_` operations bypass the model methods and operate directly by executing SQL. (See [QuerySet API reference | Django documentation | Django](https://docs.djangoproject.com/en/4.1/ref/models/querysets/#bulk-create)) If you want the data validated before insertion, you’ll need to ensure it happens either way.
