1

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?

djangoliv
  • 1,698
  • 14
  • 26

1 Answers1

1

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.

Risadinha
  • 16,058
  • 2
  • 88
  • 91
  • Thanks, but the Django internal model is duplicated too (auth tables for example). Maybe, this is not a real problem... – djangoliv Feb 06 '17 at 16:25
  • Maybe you should explain what you want to solve by doing this? (Edit your question or create a new one in that case.) Maybe using two different databases is not the best way. Maybe two Models that inherit from an abstract model are better. Or even using the `site` framework might be what you actually need. – Risadinha Feb 07 '17 at 09:07