How to import database into Django models?

2

I have an application that is almost ready. It was developed in PHP through the Laravel Framework.

I already have the database and all some data already entered to perform tests.

However, since I'm doing some tests with the Django framework, I would like to use this database from the previous application and use it in Django.

That is, I wanted to know if you have any reverse engineering, where I can create% django% from an existing database.

Details: My database is models .

    
asked by anonymous 02.05.2016 / 02:13

1 answer

5

Yes, the Django framework has a ready-made tool for this.

This is the inspectdb command.

This command will cause Django to analyze your database and generate an output containing definitions of models. That is, your database abstraction will be automatically generated by Django for the inspected tables.

You can capture this output to a Python file using the > operator.

Then, after setting Mysql to your settings.py of Django, just do this:

 ./manager.py inspectdb > app/models.py
    
02.05.2016 / 02:13