Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Django Apps using Same Database Table [duplicate]

If I have two Django apps in the same project and both apps need to use the same table in the same database, how should I describe this table in two different models.py files?

like image 894
John Joseph Z Avatar asked Dec 18 '25 21:12

John Joseph Z


1 Answers

If you declare a table in two separate apps within the django project you will have two separate tables. What you want to do is declare the model in the app where it makes the most sense and then import the model from the second app.

For example:

#app2.views

from app1.models import MyModel

Like this you will be referencing the same table from both locations and you won't have any weird situation in which you look for data and you don't find it.

like image 126
Beikeni Avatar answered Dec 20 '25 09:12

Beikeni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!