#27908: Cannot use 'schema.table' with 'inspectdb'
-------------------------------------+-------------------------------------
Reporter: Jaap | Owner: nobody
Vermeulen |
Type: Bug | Status: new
Component: Core | Version: 1.10
(Management commands) |
Severity: Normal | Keywords: inspectdb
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I tried inspecting a table in a different schema with Django 1.10.6 and
python 3.4.5 and postgres 9.2.18 on RHEL7.
Looks like the 'inspectdb' doesn't really handle that. You can get past
the first error (table not found) with:
python3 manage.py inspectdb '"schema"."table"'
by tricking the quoting code in quote_name() in
db/backends/postgresql/operations.py, but it still goes wrong for the code
that figures out NULLable. Here are 2 snippets of code that will at least
make it possible to inspect tables in a different schema (I didn't peel a
git clone just for this; use it if you think it's useful):
db/backends/postgresql/operations.py:
{{{
def quote_name(self, name):
if name.startswith('"') and name.endswith('"'):
return name # Quoting once is enough.
# Quote db and schema names separately
parts = name.split('.')
quoted_name = ""
seperator = ''
for part in name.split('.'):
quoted_name += seperator
quoted_name += '"%s"' % part
seperator = '.'
return quoted_name
def unquote_name(self, name):
if name.startswith('"') and name.endswith('"'):
name = name[1:-1]
# Quote only name
parts = name.split('.')
return "%s" % parts[-1]
}}}
db/backends/postgresql/introspection.py:
{{{
def get_table_description(...):
...
cursor.execute("""
SELECT column_name, is_nullable, column_default
FROM information_schema.columns
WHERE table_name = %s""",
[self.connection.ops.unquote_name(table_name)])
...
}}}
Note that the code is crummy at best. Really, to deal with schemas you
should look at both the table_name and the schema_name as needed for the
information_schema.columns. But as long as your table name is unique,
this at least works for now.
--
Ticket URL: <https://code.djangoproject.com/ticket/27908>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/056.fe6cd83b8bedd3379358589cd4d5ddb0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.