29

Our website uses a PHP front-end and a PostgreSQL database. We don't have a back-end at the moment except phpPgAdmin. The database admin has to type data into phpPgAmin manually, which is error-prone and tedious. We want to use Django to build a back-end.

The database has a few dozen of tables already there. Is it possible to import the database schema into Django and create models automatically?

1
  • 1
    That's an odd usage of the terms "front-end" and "back-end". PHP would be your back-end; it sounds like you're simply talking about building an admin panel to go with it. Commented Oct 24, 2013 at 21:02

2 Answers 2

54

Yes it is possible, using the inspectdb command:

python manage.py inspectdb

or

python manage.py inspectdb > models.py

to get them in into the file

This will look at the database configured in your settings.py and outputs model classes to standard output.

As Ignacio pointed out, there is a guide for your situation in the documentation.

Sign up to request clarification or add additional context in comments.

Comments

2

If each table has an autoincrement integer PK then you can use the legacy database instructions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.