Issue
I'd like to use inspectdb in order to build corresponding models for freshly introduced tables. But is looks like this command only looks up the public
schema, while the new tables are in another one.
Is it possible to specify a schema to inspectdb
?
Solution
Based on this Gist, I modified django.core.management.commands.inspectdb
: around line 32, in handle_inspection()
, after cursor = connection.cursor()
, add cursor.execute("SET search_path TO myotherschema")
.
def handle_inspection(self, options):
connection = connections[options.get('database')]
table2model = lambda table_name: table_name.title().replace('_', '').replace(' ', '').replace('-', '')
cursor = connection.cursor()
cursor.execute("SET search_path TO myotherschema")
# [...]
As of, at least, Django 1.9:
def handle_inspection(self, options):
# [...]
with connection.cursor() as cursor:
cursor.execute("SET search_path TO myotherschema")
# [...]
Answered By - Anto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.