Multiple Databases

21 views
Skip to first unread message

Luvpreet Singh

unread,
Feb 27, 2017, 2:17:44 AM2/27/17
to Django users
Hi everyone,

I am using 2 databases in my django app. One is default sqlite and second is postgre.

Now, I make a simple model named Check1 in my app, having only title attribute.

class Check1(models.Model):
      title = models.CharField(max_length=100)

Now, in my shell,

>> from check.models import Check1
>> a = Check1(title="first")
>> a.save()
>> Check1.objects.all()   --> this gives the queryset returning 'first'


My question is, in which database is it saved, means in my default db or my postgre db ? or in both ?

>> Check1.objects.using('default').all()    --> it gives me error
>> Check1.objects.using('newpostgre').all()  --> it gives me correct queryset.

How does I know or set that in which db it will be saved ?

Dylan Reinhold

unread,
Feb 27, 2017, 2:39:24 AM2/27/17
to django...@googlegroups.com
It is going to use the database named default.
Checkout the doc on using mutiple DBs
https://docs.djangoproject.com/en/1.10/topics/db/multi-db/

Dylan


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@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/3c65b2a4-d409-44a6-8ea9-73aa15989eb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luvpreet Singh

unread,
Feb 27, 2017, 4:02:47 AM2/27/17
to django...@googlegroups.com
But dylan, I have written that

Check1.objects.using('default').all()

gives me error.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/5sxIoy0mDcE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

ludovic coues

unread,
Feb 27, 2017, 4:21:26 AM2/27/17
to django...@googlegroups.com
Have you checked your settings for typo ?
>>> email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@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/3c65b2a4-d409-44a6-8ea9-73aa15989eb2%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/5sxIoy0mDcE/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> django-users...@googlegroups.com.
>> To post to this group, send email to django...@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/CAHtg44BO8P5N-AfYvCjPnBn2p_GxRK9HQ_SRiUw8PWgWfKdtfA%40mail.gmail.com.
>>
>> For more options, visit 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...@googlegroups.com.
> To post to this group, send email to django...@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/CAL%2BrqijFBegKbKGmSAZgFEFpJWn75hVoCOYxPJi%3DLHFBrNs_FQ%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42
Reply all
Reply to author
Forward
0 new messages