Have a look here:

https://docs.djangoproject.com/en/1.11/topics/db/multi-db/ 
<https://docs.djangoproject.com/en/1.11/topics/db/multi-db/>

Basically:

>>> # This will run on the 'default' database.
>>> Author.objects.all()

>>> # So will this.
>>> Author.objects.using('default').all()

>>> # This will run on the 'other' database.
>>> Author.objects.using('other').all()

> On 2 Aug 2017, at 12:47, kartik danidhariya <kartikdanidhar...@gmail.com> 
> wrote:
> 
> 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 
> <https://stackoverflow.com/questions/18547468/multiple-databases-and-multiple-models-in-django>
>  but it prefers only default database only after that i tried with put blank 
> setting in default database and try ti migrate but it gives me an error
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/10ce81e3-674f-4c2e-b4ad-0215f3d1aff2%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/10ce81e3-674f-4c2e-b4ad-0215f3d1aff2%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/A783E9F8-C077-4A63-A514-5B94FC34134F%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to