Opened 14 years ago

Closed 14 years ago

#15781 closed Bug (invalid)

Multiple databases with same model names causing get errors

Reported by: anonymous Owned by: Michael Radziej
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: no

Description

Code that causes the problem:

everyone.py:
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

people.py:
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 (view.py):

try:

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 by anonymous, 14 years ago

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 by Michael Radziej, 14 years ago

Easy pickings: unset
Owner: changed from nobody to Michael Radziej
Status: newassigned

comment:3 by Michael Radziej, 14 years ago

Resolution: invalid
Status: assignedclosed

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