Is there a way to see manage.py sql output of "managed=False" models?

26 views
Skip to first unread message

Serdar Dalgic

unread,
Apr 2, 2013, 3:46:10 PM4/2/13
to django...@googlegroups.com
Hi;

In my project, we are using django 1.3.2, and we're on the verge of
migrating to 1.4.
I wrote a standalone app, in which I've created some models with

class Meta:
managed = False

setting in every model class. (The reason why I did like this is, I
prefer to use a different DB than the default one for mapping those
models.)
Now, I want to create the tables on my **app_db_name** DB, so I use the command

python manage.py sqlall appname --database=app_db_name

However this manage.py sql(all) commands checks for the models and if
they are set to be managed by the users, this command gives no
outputs.

So, I've hacked into the code a little, and found that
**django.db.backends.creation** module's **sql_create_model()**
function has such a check:

def sql_create_model(self, model, style, known_models=set()):
"""
Returns the SQL required to create a single model, as a tuple of:
(list_of_sql, pending_references_dict)
"""
....
if not opts.managed or opts.proxy:
return [], {}
....

So I solved my problem by commenting out this if clause.

What I want to ask is, is there a better way of seeing my managed
models' sql create statements?
I'd prefer to have an option like "--show-managed" to "python
manage.py sql" or sqlall commands, so that this can me done.

What are your comments on this issue?

Thanks.

--
- Serdar Dalgıç <s...@serdardalgic.org>
FLOSS Developer, Life & Nature Hacker

Bill Freeman

unread,
Apr 2, 2013, 4:48:04 PM4/2/13
to django-users
Perhaps take the site down (or clone it), set managed = True, ask manage.py for sql for that app, and put everything back?


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



Serdar Dalgic

unread,
Apr 2, 2013, 4:57:01 PM4/2/13
to django...@googlegroups.com
On Tue, Apr 2, 2013 at 11:48 PM, Bill Freeman <ke1...@gmail.com> wrote:
> Perhaps take the site down (or clone it), set managed = True, ask manage.py
> for sql for that app, and put everything back?
>

Sure, that's a way to do it. But I'm looking for a practical way to do
it. Otherwise, commenting out the managed=True lines in the models.py
is an option too :)

Bill Freeman

unread,
Apr 2, 2013, 5:02:22 PM4/2/13
to django-users
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Yes.  I must confess that I like your solution better.  But some folks are loth to edit the stuff that isn't their code.

Maybe create a patch adding a command line flag that says you want the unmanaged moddels as well, and offer it to the core team?  Them taking it, however, wouldn't help you with 1.3.2.

Serdar Dalgic

unread,
Apr 2, 2013, 5:20:21 PM4/2/13
to django...@googlegroups.com
On Wed, Apr 3, 2013 at 12:02 AM, Bill Freeman <ke1...@gmail.com> wrote:
>
> Yes. I must confess that I like your solution better. But some folks are
> loth to edit the stuff that isn't their code.
>

Thanks. Yeah, there is such behavior among folks.

> Maybe create a patch adding a command line flag that says you want the
> unmanaged moddels as well, and offer it to the core team? Them taking it,
> however, wouldn't help you with 1.3.2.
>

Yeap, I'm aware of this. I'll create a ticket on this issue then, and
provide the patch for the current codebase. Before doing this, I
wanted to ask to django-users group whether I'm missing smt or not.
Thanks for your feedback.
Reply all
Reply to author
Forward
0 new messages