Hi,
let’s say I have tow databases: (db.sqlite3 and measure.db.sqlite3)
I am using routers to manipulate those databases so my question is how to set a ForeignKey from a measure.db and SurveillanceDesPuits table to another table in db,
in the first db I have this table
class Wellinfo(models.Model):
WellID = models.CharField(max_length=15,unique=True)
def __str__(self):
return self.WellID
and in the second database I have this table :
class SurveillanceDesPuits (models.Model):
WellID = models.CharField(max_length=15,unique=True) # this field is related to the old database and table
fields = models.CharField(max_length=15)
def __str__(self):
return self.WellID
knowing that my routers.py is configured as:
from os import read
class AuthRouter:
route_app_labels = {'auth', 'contenttypes','sessions','admin','Home','user'}
def db_for_read(self, model, **hints):
if model._meta.app_label in self.route_app_labels:
return 'default'
return None
def db_for_write(self, model, **hints):
if model._meta.app_label in self.route_app_labels:
return 'default'
return None
def allow_relation(self, obj1, obj2, **hints):
if (
obj1._meta.app_label in self.route_app_labels or
obj2._meta.app_label in self.route_app_labels
):
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label in self.route_app_labels:
return db == 'default'
return None
class Measure:
route_app_labels = {'measure'}
def db_for_read(self, model, **hints):
if model._meta.app_label in self.route_app_labels:
return 'measure_db'
return None
def db_for_write(self, model, **hints):
if model._meta.app_label in self.route_app_labels:
return 'measure_db'
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label in self.route_app_labels:
return db == 'measure_db'
return None