2

To save a model to my 'not_default_db' I'm using :

 p = Person(name='James')
 p.save(using='not_default_db') 

But using Model.create() save the model in the default DB:

Person.objects.create(name='James')

Is it possible to use Model.create() on a specifc Data Base ?

1
  • You have to specify multiple database in your settings.py file. You can read the Django documentation (docs.djangoproject.com/fr/2.0/topics/db/multi-db). Then, I suspect issue in your request. Commented May 24, 2018 at 9:59

1 Answer 1

4

Try to use queryset's using() method:

Person.objects.using('not_default_db').create(name='James')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.