Opened 5 years ago

Closed 5 years ago

#15781 closed Bug (invalid)

Multiple databases with same model names causing get errors

Reported by: anonymous Owned by: mir
Component: Uncategorized Version: 1.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX:


Code that causes the problem:
class Person(models.Model):

emplid = models.CharField(max_length=15,primary_key=True)
... (other fields deleted)

class Meta:

app_label = u'everyone'
db_tablespace = u'everyone'
db_table = u'people_names'
managed = False
class Person(models.Model):

emplid = models.CharField(max_length=11, db_column='emplid', primary_key=True

) ... (other fields deleted)

class Meta:

app_label = u'commons'
db_tablespace = u'people'
db_table = u'person'

The 2nd people.Person model is my default db, so #1 is "everyone.Person" and #2 is just "Person".

I tried (


person = everyone.Person.objects.get(pk=emplid)

except everyone.Person.DoesNotExist: # person not found by "get"

do some stuff

django complains in the 'except' : global name 'everyone' is not defined.

Apparently django does not support multi-database models in the same way as the default database. There is a work-around, but this behaviour then is inconsistent with default database models. Don't know if this is due to model names being the same.

Change History (3)

comment:1 Changed 5 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Work around is to include:

from everyone import Person as SomeOtherModelName

then use SomeOtherModelName.objects.get(pk=emplid)

This seems like a cluge?

comment:2 Changed 5 years ago by mir

  • Easy pickings unset
  • Owner changed from nobody to mir
  • Status changed from new to assigned

comment:3 Changed 5 years ago by mir

  • Resolution set to invalid
  • Status changed from assigned to closed

This looks like a user error - you forgot to import everyone. Please post full error messages and use the right formatting for code snippets. For support, please use the django-users mailing list.

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