There are two databases: default and mart . PostgreSQL db. There are the following lines:

 site_user = SiteUser.objects.using('mart').get(id=1) site_user.save(using='default', force_insert=True) site_user = SiteUser.objects.using('default').get(id=1) 

On the third line, an error occurs that such site_user not found. Although the second line (if you believe the documentation ) should ensure that such site_user created in the default database (otherwise an error will take off).

What could be the problem?

    1 answer 1

    Hi, I have Django 1.7.3. I created a mart database and tried to reproduce

     In [1]: from products.models import Color In [3]: Color.objects.using('mart').count() Out[3]: 0 In [2]: Color.objects.using('default').count() Out[2]: 16 In [3]: c = Color.objects.using('default').get(pk=1) In [4]: c.save(using='mart', force_insert=True) In [5]: Color.objects.using('mart').get(pk=1) Out[5]: <Color: Black> In [6]: Color.objects.using('mart').count() Out[6]: 1 

    but I have not reproduced your problem. What is your version of Django? And show the options DATABASES ['default'] ['OPTIONS'], if any

    • one
      Thanks for the help! There really is no mistake, it turned out that a colleague made a typo in inheriting save (force_insert was always False), but I did not notice it ( - Zhassulan Nurushev