I use django (2, 1, 5, 'final', 0).
My problem, i try to store an address model in postgresql, all the others models (auth, products...) in mongodb engine with the djongo package. the models stored in app => geolocalise :
class Address(models.Model):
line1 = models.CharField(max_length=150)
line2 = models.CharField(max_length=150, blank=True)
postalcode = models.CharField(max_length=10)
city = models.CharField(max_length=150)
country = models.CharField(max_length=150, default="France")
#the postgis entry
location = models.PointField(null=True)
latitude = models.FloatField( default=0)
longitude = models.FloatField( default=0)
description = models.TextField(max_length=1024,blank=True)
#user = models.ForeignKey('User', related_name='user', on_delete=models.CASCADE)
def __str__(self):
return "{0} - {1} - {2}".format(self.line1, self.postalcode, self.city)
here my settings py
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'DBNAME',
'USER': 'USER',
'PASSWORD': 'PASSWORD'},
'postgresql': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'DBNAME',
'USER': 'USER',
'PASSWORD': 'PASSWORD'}}
But when i do my migrations i don't know why the database is store in mongodb.
I've try a configuration in a router.py which i found on stackoverflow but it's isn't working:
class GeolocaliseRouter(object):
def db_for_read(self, model, **hints):
"""
Attempts to read auth models go to auth_db.
"""
if model._meta.app_label == 'geolocalise':
return 'postgresql'
return None
def db_for_write(self, model, **hints):
"""
Attempts to write auth models go to auth_db.
"""
if model._meta.app_label == 'geolocalise':
return 'postgresql'
return None
def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the auth app is involved.
"""
if obj1._meta.app_label == 'geolocalise' or \
obj2._meta.app_label == 'geolocalise':
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
"""
Make sure the auth app only appears in the 'auth_db'
database.
"""
if app_label == 'geolocalise':
return db == 'postgresql'
return None
I've tested multiple configuration but anytimes i do the migration the model is in mongodb or all the models of my project go in postgresql....
I'm new in django and thank you for any futher assistance