I'm finding myself with a django project handling two distinct classes mapped on a similar table name:
class BarA(models.Model):
[...]
class Meta:
db_table = 'bar' # doesn't specify any schema
class BarB(models.Model):
[...]
class Meta:
db_table = u'foo"."bar'
The project is using a database containing two schemas: public
and foo
.
The way this application is templated and deployed makes things even more confusing: on some servers, django connects to database with the user "John", not member of any role, but on other servers it connects with user "Eric", member of a foo
role.
Two questions here:
- If django's meta class doesn't mention any specific schema, how does Postgres decide which table it will work with ? So far, it appears that user Eric will always hit the
foo.bar
table, and never thepublic.bar
one, regardless of the called class. With user "John", I'm only usingBarA
class and it properly hitspublic.bar
. - Django doesn't seem to handle schemas; is this solution considered as a good practice for that kind of case (please note that I cannot rename the existing tables)?