I've been picking apart this problem for about a week. I have looked at all of the other stackoverflow posts and cant figure it out. Anyway, I'm trying to add a geodjango app to my project. This project is still in development, anyway, I have two databases, the default and one labeled locations_db. I want my geodjango functionality in the locations database and all the other stuff in the default database. The locations database is a postGIS database that is working fine and the default is a mysql database. I have tested the locations database using postGIS shell and I started a new django project and made it pure geodjango. Both worked fine. However when I attempt to run any kind of manage.py command, it throws the error: 'DatabaseOperations' object has no attribute 'geo_db_type'. I tried migrating with the --database option and using a database router. How can I resolve this issue? For reference, here is my settings.py excerpt concerning the databases:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'xxxx',
"USER":"xxxx",
"PASSWORD":"xxxxxxxxx",
'HOST': 'xxxxxxxxxx',
'PORT': 'xxxx',
},
'locations_db':{
'ENGINE':"django.contrib.gis.db.backends.postgis",
'NAME': 'xxxxxxxxxx',
"USER":"xxxxxxxxx",
"PASSWORD":"xxxxxxxxxxxxxxxx",
'HOST': 'xxxxxxxxx',
'PORT': 'xxxx',
}
}
...
DATABASE_ROUTERS = ['locations.router.Router']
DATABASES['locations_db']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
Here is my router:
class Router(object):
def db_for_read(self, model, **hints):
"Point all operations on locations models to 'locationsdb'"
if model._meta.app_label == 'locations':
return 'locations_db'
return None
def db_for_write(self, model, **hints):
"Point all operations on locations models to 'locationsdb'"
# print("working not in locations?")
if model._meta.app_label == 'locations':
print(model._meta.app_label)
return 'locations_db'
return None
def allow_relation(self, obj1, obj2, **hints):
"Allow any relation if a both models in locations app"
# if obj1._meta.app_label == 'locations' and obj2._meta.app_label == 'locations':
# return True
# # Allow if neither is locations app
# elif 'locations' not in [obj1._meta.app_label, obj2._meta.app_label]:
# return True
if(obj2._meta.app_label == 'locations' or obj1._meta.app_label == "locations"):
return True
return None
def allow_migrate(self, db, model):
if(db == "locations_db"):
return model._meta.app_label == 'locations'
elif model._meta.app_label == 'locations':
return False
else:
return None
def allow_syncdb(self, db, model):
# print("working not in locations?")
if db == 'locations_db' or model._meta.app_label == "locations":
print(model._meta.app_label)
return False # we're not using syncdb on our legacy database
else: # but all other models/databases are fine
return True
and my model:
class Locations(models.Model):
name = models.CharField(max_length=254)
area = models.IntegerField()
pop2005 = models.IntegerField('Population 2005')
fips = models.CharField('FIPS Code', max_length=2)
iso2 = models.CharField('2 Digit ISO', max_length=2)
iso3 = models.CharField('3 Digit ISO', max_length=3)
un = models.IntegerField('United Nations Code')
region = models.IntegerField('Region Code')
subregion = models.IntegerField('Sub-Region Code')
lon = models.FloatField()
lat = models.FloatField()
# GeoDjango-specific: a geometry field (MultiPolygonField), and
# overriding the default manager with a GeoManager instance.
mpoly = models.PolygonField()
objects = models.GeoManager()
Thank you in advance for your assistance!
EDIT: I am using django 1.8 aka the Development version. postGIS version 2.1 and postgres version 9.3