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

8👍

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

2👍

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.

👤sc28

-2👍

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.

👤1GDST

Leave a comment