0

I have used DB routers for apps, but after running migrate command tables are created in default DB, why??

model code:

from django.db import models

# Create your models here.
class Employee(models.Model):

      Employee_id = models.AutoField(primary_key=True)
      Employee_name = models.CharField(max_length=100)
      Mobile_number = models.IntegerField()
Hassan Raza
  • 106
  • 12
  • How are you running you migrate command. Are you explicitly specifying what DB to use? Please refer "https://docs.djangoproject.com/en/2.0/topics/db/multi-db/#synchronizing-your-databases" documentation to make sure that you are doing it right. – Krushi Raj Jun 28 '18 at 07:48
  • thanks @KrushiRaj it worked – Hassan Raza Jun 28 '18 at 07:52

1 Answers1

0

Finally this worked for me

Synchronizing your databases The migrate management command operates on one database at a time. By default, it operates on the default database, but by providing the --database option, you can tell it to synchronize a different database. So, to synchronize all models onto all databases in the first example above, you would need to call:

$ ./manage.py migrate
$ ./manage.py migrate --database=users

If you don’t want every application to be synchronized onto a particular database, you can define a database router that implements a policy constraining the availability of particular models.

If, as in the second example above, you’ve left the default database empty, you must provide a database name each time you run migrate. Omitting the database name would raise an error. For the second example:

$ ./manage.py migrate --database=users
$ ./manage.py migrate --database=customers
Hassan Raza
  • 106
  • 12