Opened 5 years ago

Closed 5 years ago

#25514 closed Bug (duplicate)

Unique field - _perform_unique_checks problem

Reported by: arannasousa Owned by:
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: unique key checks
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Sorry for the bad English (translated via Google).

I have a correction suggest.

Currently working with different database without be 'default'.
One of my classes has a field with the 'unique = True' on.

When trying to make the register for a new item, via django.forms.ModelForm, page back me an error: "Database of not exists" (because is other database)

This was why the django was to perform a query from behind, to see if there is not any registered item that is equal to, but he did not know which database to look.

My suggestion is as follows:

version: 'development'
the file: 'django.db.models.base.py'
lines: 1006 and 1043

change from:

qs = model_class._default_manager.filter(**lookup_kwargs)

to:

qs = model_class._default_manager.using(getattr(self, 'db', None)).filter(**lookup_kwargs)

Thus, problems with UNIQUE fields in different banks 'default' ended

Change History (1)

comment:1 Changed 5 years ago by Tim Graham

Component: UncategorizedDatabase layer (models, ORM)
Resolution: duplicate
Status: newclosed
Type: UncategorizedBug

Looks like a duplicate of #15130.

Note: See TracTickets for help on using tickets.
Back to Top