I just tried to find a solution for define database model wise in Django. like in my settings.py there are three databases
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'db_one': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db_one.sqlite3'),
},
'db_two': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db_two.sqlite3'),
},
}
And in my polls/models.py
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
@python_2_unicode_compatible
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
now I want to add question model in db_one database and Choice model in db_two database so how can I do that
I try with routers follow this multiple databases and multiple models in django but it prefers only default database only after that I tried with put the blank setting in default database and try to migrate but it gives me an error
or
is that way to define a database for application wise in Django