Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data from database without models in django?

I have been crawling around its doc but mostly it uses database with model.

The problem is my database is too large and I don't want to create any models

since it's legacy one, and I will have to call different tables dynamically,

so I just want to pull data from it. Is that possible in django?

like image 314
cnjap Avatar asked Nov 29 '16 18:11

cnjap


2 Answers

You can go around the model layer and use sql directly. However, you will have to process the tables in python, not having the advantage of using ORM objects.

https://docs.djangoproject.com/en/1.10/topics/db/sql/#executing-custom-sql-directly

like image 72
joecascio Avatar answered Oct 19 '22 17:10

joecascio


As pointed out in a comment, Django provides a way to automatically generate the models from the legacy database with inspectdb. This guide describes the few manual steps required to "clean" the automatically generated models.

While this doesn't directly answer the stated question of avoiding models, it does address your issue of not wanting to create them yourself, due to the large database.

like image 1
sc28 Avatar answered Oct 19 '22 17:10

sc28