GeoDjango error: DatabaseOperations object has no attribute 'geo_db_type'

I picked this issue for about a week. I've looked at all other stackoverflow posts and can't figure it out. Anyway, I am trying to add a geodjango app to my project. Anyway, this project is still in development, I have two databases, the default and one marked with location_db. I want my geodjango functions to appear in the location database and other databases by default. The location database is the postGIS database which works fine and the default is the mysql database. I checked out the location database using the postGIS wrapper and I started a new django project and made it clean geodjango. Both worked fine. However, when I try to run any manage.py command, it gives the error: "DatabaseOperations object" does not have a "geo_db_type" attribute.I tried to migrate with the --database parameter and using the database router. How can I solve this problem? For reference, here is my settings.py excerpt regarding 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 help!

EDIT: I am using django 1.8 and also the development version. postGIS version 2.1 and postgres version 9.3

+3


source to share





All Articles