Search code examples
djangomulti-database

Django multi-database, one model


In my Django project, I would like two databases but only one model.

For example, an expert database and an exploit database. The router allows me to write in the exploit database or the expert database according to the users groups and permissions.

But how to duplicate the project model (described in model.py) in both bases?


Solution

  • You need to run migrate on each database. Use this switch to specify the database:

    --database DATABASE   Nominates a database to synchronize. Defaults to the
                        "default" database.
    

    DATABASE in this case is the settings key that you are using in your settings.py field to configure each database.