3

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

6
  • 1
    Possible duplicate of: stackoverflow.com/questions/12538510/… Commented Nov 30, 2014 at 23:30
  • @karthikr read that, As you see in my excerpt from my settings.py, the solution on that post is included at the bottom. Also I am not using heroku or using a build pack from them. Commented Nov 30, 2014 at 23:34
  • if db == 'locationsdb' in allow_syncdb should be if db == 'locations_db' ? Commented Dec 1, 2014 at 2:00
  • @Anentropic The only reason I changed it to locations_db is because it wasn't working and wanted to see if you needed _db for some reason. originally it was locationsdb Commented Dec 1, 2014 at 3:17
  • 1
    @Anentropic That is just a victim of copy and paste. Its consistent in my actual code.I just edited to reflect those issues. Commented Dec 1, 2014 at 13:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.