My current project is getting extended with geographical stuff, so I'm trying to integrate GeoDjango and import some shapefiles for starters. My setup consists of the following:
South
is being used throughout the projectNow I've created a GeoDjango model in a new app for my areas. As usual, I've done ./manage.py schemamigration --initial
and when I tried doing ./manage.py migrate $my_new_app --database="gis"
, it failed with django.db.utils.DatabaseError: no such table: south_migrationhistory
, which is I guess correct, since south_migrationhistory
is in my main database.
Does anyone have any experience with such setups and can help me out?
EDIT: I've changed the title, since I realized this question is not actually GeoDjango-specific.
Within systematic reviews, when searching for relevant references, it is advisable to use multiple databases. However, searching databases is laborious and time-consuming, as syntax of search strategies are database specific.
Multiple database technologies can be used with monolithic applications, and can even seem more natural in a microservices environment, where each service would have its own database. This approach, however, is not bulletproof. Far from it, actually.
so, based on user login, the application should connect different database server. For Ex: if user "xxx" login with credential and belogs to "ABC" company and the database is "ABC", then ABC data need to display on the web page.
Grouping of data into multiple databases each with a significantly fewer number of tables. In terms of flexibility, it's much simpler to use a single database with a single copy of the tables. It's easier to manage. A single database would most likely have a single set of servers, meaning one location.
My improved soultion:
To create the table south_migrationhistory
in the other database:
./manage.py syncdb --database="my_db_name_for_apps"
You can now use a standard :
./manage.py migrate my_app
Here is my actual db_router.py
# -*- coding: UTF-8 -*- apps =['app1', 'app2' ] db_name = 'my_db_name_for_apps' class sh_router(object): """A router to control all database operations on models from applications in apps""" def db_for_read(self, model, **hints): """Point all operations on apps models to db_name""" if model._meta.app_label in apps : return db_name return None def db_for_write(self, model, **hints): """Point all operations on apps models to db_name""" if model._meta.app_label in apps: return db_name return None def allow_relation(self, obj1, obj2, **hints): """Allow any relation if a model in apps is involved""" if obj1._meta.app_label in apps or obj2._meta.app_label in apps: return True return None def allow_syncdb(self, db, model): """Make sure the apps only appears on the db_name db""" if model._meta.app_label in ['south']: return True if db == db_name: return model._meta.app_label in apps elif model._meta.app_label in apps: return False return None
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With