1
votes

I am relatively new to Django. I have managed to create a basic app and all that without problems and it works fine.

The question probably has been asked before. Is there a way to update existing Django models already mapped to existing databases when the underlying database is modified?

To be specific, I have mysql database that I use for my Django app as well as some standalone python and R scripts. Now, it is much easier to update the mysql database with, say, daily stock prices, everyday from my existing scripts outside Django models. Ideally, what I would like is to have my Django models that are already mapped to these tables to reflect the updated data.

I know there is $ python manage.py inspectdb for creating models from existing databases. But that is not the objective.

From what I have gathered so far from the docs and online searches, it is imperative to update the backend database through Django models. Not outside of it. Is it the case really? As long as the table structure doesn;t change I really don't see the why this should not be allowed. Database is meant to serve multiple customers isn't it? With Django being one of it.

And I can not provide a reproducible example as it is a conceptual question. If this functionality doesn't exist, imho, it really should.

Thanks, Kaustubh

1
I don't understand what you're asking. If Django is using the same database, then there is nothing to update; Django will already see the updated information. - Daniel Roseman
Please remove the django-mysql label from this question, it's intended for the library django-mysql not "django with mysql" - Adam Johnson
As an aside, you should consider not allowing external applications having direct access to a Django-'controlled' database. You are relying on (your) external code to behave in a way that the Django ORM (database layer) expects. Look into Django management commands if you want to alter the database in a Django-sanctioned way via the command-line. - Kye Russell

1 Answers

4
votes

You don't need to update models if you just added new data. Models are related to a database structure only.