Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import MySQL tables into Django

I have recently created a PHP application which connects to my MySQL database and displays the table information. Where Django is concerned, I am only familiar with them being created in SQLite by creating the relevant models.

Is there a way to do this in reverse? So have Django create models from the tables in MySQL?

like image 430
Jon Avatar asked Jan 31 '26 15:01

Jon


1 Answers

You can use your existing schema to create tables. The official documentation is at: https://docs.djangoproject.com/en/1.7/howto/legacy-databases/

There are two commands:

python manage.py inspectdb

This will give you the output of running:

python manage.py inspectdb > models.py

Django won't know how you want to break these models up into separate application modules, so you'll need to do that on your own, if necessary.

like image 112
Brandon Avatar answered Feb 03 '26 04:02

Brandon