Jieke Wei
Jieke Wei

Reputation: 183

Django - Model.py

Just a simple question.

After I connect my django app to a remote database, I don't need to use Model.py to create tables in the database, then what is the function for Model.py at that moment?

Upvotes: 1

Views: 99

Answers (2)

N. L. Long
N. L. Long

Reputation: 179

If you want to use the Django ORM, you'll need to create models in the models.py file that match your remote database. If you don't want django creating or deleting tables on this DB, the managed=False option needs to be set for each model. https://docs.djangoproject.com/en/1.11/ref/models/options/#managed

Upvotes: 1

Ajai
Ajai

Reputation: 901

As you said after running migrations all tables in models.py file will be created. Later on, if you want to do some database operations, you may be using Django ORM. If you don't have models.py you won't be able to do such operations.

For example: To create an entry to the table MyModel.

from your_app.models import MyModel
MyModel.objects.create(<field_name>=<value>)

I hope this gives you some idea.

Upvotes: 1

Related Questions