0

I have Django project and I want to migrate one table (that table isn't defined like a Django class in model.py, but it is exist in PostgreSQL DB) from PostgreSQL to Django.

Which instrument can be used to create class from exist table in Database?

Philipp
  • 2,787
  • 2
  • 25
  • 27
Tyomik_mnemonic
  • 786
  • 3
  • 9
  • 31

1 Answers1

3

You can auto generate models with:

$ python manage.py inspectdb

in order to save the output to a file:

$ python manage.py inspectdb > models_from_db.py

read inspectdb for more detail.

You can get generate for just one table passing the table name to the command:

$ python manage.py inspectdb table > models_from_db.py
Raydel Miranda
  • 13,825
  • 3
  • 38
  • 60
  • @RaydelMiranda if I will to initiate inspectdb, whole database will generated in one models.py file? Could I to startapp in my project and to generate one particullary class from one particullary table from databast? – Tyomik_mnemonic Feb 05 '19 at 08:40
  • 1
    @Tyomik_mnemonic I add such case at the end if you want the command output to be appended to your existing models.py use `>>` instead of `>`. – Raydel Miranda Feb 05 '19 at 08:42
  • @RaydelMiranda I need it for event, when I have some classes in model, and whant generate class from one particulary table (many to many table) from exist database.. – Tyomik_mnemonic Feb 05 '19 at 08:43