[Solved]-How to get data from database without models in django?


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.



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.



Data should be stored somewhere. There are a lot of ways to store data, but the most reliable one is a database (hence the name).

You could be storing data in a JSON file and save that. You could also be storing data in environment variables. You can even store data in a plain text file. All of those are NOT recommended. I would just try to use a database, any type of database (MongoDB / Postgres / MySQL, anything). That’s what it is meant for.


Leave a comment