I have two databases to connect to for my Django App. I have only read access for one of the database, from where I want to pull only a few columns for my model into the other database where I have read and write access. It does not make sense to 'inspectdb' the read access databases with 100+ tables and the 100+ columns for just a few columns.
How do I add the column from another database to my existing model in the simplest manner using a join? Can I use a raw sql query with parameters to add the field into my model?
class APPNAME(models.Model):
class Meta:
db_table = 'APPNAME'
item= models.PositiveIntegerField(db_column='Item')
issue = models.CharField(max_length=200, db_column='Issue')
detail = models.TextField(db_column='Detail')
created_at = models.DateTimeField(auto_now_add=True, db_column='Create Datetime')
updated_at = models.DateTimeField(auto_now=True, db_column='Update Datetime')
external_column = How to join this column???
Here is a simple SQL Query to showcase what I am trying to do with the Django model.
SELECT
APP.[Item]
,APP.[Issue]
,APP.[Detail]
,APP.[Create Datetime]
,APP.[Update Datetime]
,BIG.[External Column]
FROM DEVDB.dbo.APPNAME APP
INNER JOIN PRODDB.dbo.BIGTABLE BIG ON APP.[Item] = BIG.[Item]