Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is using multiple databases and South together possible?

Tags:

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:

  1. MySQL 5.0 as 'default' database, previously the only database.
  2. Spatialite as 'gis' database, should only be used to import areas from shapefiles
  3. South is being used throughout the project

Now 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.

like image 773
Nikolai Prokoschenko Avatar asked Aug 11 '11 16:08

Nikolai Prokoschenko


People also ask

Is it good to use multiple database?

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.

Can an application have two databases?

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.

How do I link multiple databases to one application?

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.

Why do we need multiple databases?

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.


1 Answers

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 
like image 135
Pierre-Jean Coudert Avatar answered Nov 09 '22 01:11

Pierre-Jean Coudert