In my django project, I am using an existing database (Postgres) and with python manage.py inspectdb
I created models.
now I want to write unit tests and my problem is django just creates an empty test database for it, but it doesn't create schemas. I need to django copy the schema of this database into the test database and then I will insert mock data into it.
Asked
Active
Viewed 208 times
1

Hamed Damirchi
- 95
- 1
- 6
-
Django should automatically apply migrations to your test database. How are you configuring your [test](https://docs.djangoproject.com/en/4.1/ref/settings/#test) database in `settings.py`? – Scratch'N'Purr Aug 15 '22 at 15:55
-
I haven't created any migrations, because I am using an existing database and I don't want to alter tables of that database. – Hamed Damirchi Aug 15 '22 at 16:00
-
1Gotcha. What you can do is still generate the migration files if you created the models. You don't have to apply the migrations to your production db (or you can fake your migrations if you want to sync your migration files to the prod db). The migration files are mainly for django to apply the schema changes to the test database when you run your test suites. – Scratch'N'Purr Aug 15 '22 at 17:00