cnjap
cnjap

Reputation: 500

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?

Upvotes: 13

Views: 19187

Answers (3)

sc28
sc28

Reputation: 1213

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.

Upvotes: 3

joecascio
joecascio

Reputation: 189

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

Upvotes: 8

1GDST
1GDST

Reputation: 821

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.

Upvotes: -2

Related Questions