How to import database for Django models?

Asked

Viewed 1,093 times

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, as I am doing some tests with the Django framework, I would like to use this database from the previous application and use it in Django.

I mean, I was wondering if you had any reverse engineering where I could create the models Django from an existing database.

Details: My database is Mysql.

  • I was punished with an -1 oppressor, kkkkk

  • I did, huh? I did not see the reason, after all I personally do not consider the question duplicate (or would have voted as such), and in any case in practical terms I liked the answer.

  • 1

    @mgibsonbr worse is that most of the time the staff of -1 for duplicate questions, but the idea of the site is not this. Duplicate questions should be closed, not negative. For the final, may be a way)

1 answer

5


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

It’s about the command inspectdb.

This command will make the Django Scan your database and generate an output containing model definitions. That is, the abstraction of your database will be automatically generated by Django for the tables inspected.

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

Then, after you set up the Mysql in his settings.py from Django, just do this:

 ./manager.py inspectdb > app/models.py

Browser other questions tagged

You are not signed in. Login or sign up in order to post.