[Django] #22775: Management command sqlall should support unmanaged models

7 views
Skip to first unread message

Django

unread,
Jun 6, 2014, 3:16:52 AM6/6/14
to django-...@googlegroups.com
#22775: Management command sqlall should support unmanaged models
--------------------------------------------+--------------------
Reporter: smeatonj | Owner: nobody
Type: New feature | Status: new
Component: Core (Management commands) | Version: master
Severity: Normal | Keywords: sqlall
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------------+--------------------
Unmanaged models are generally used with legacy database tables, but
creating those models in a development environment is also a manual
process. It'd be great if django was able to produce the sql for managed
models if explicitly asked for.

loic84, akaariai and I discussed this in IRC and came up with:

{{{
./manage sqlall applabel --include-unmanaged
}}}

The include unmanaged would print the sql necessary to create the
unmanaged models (along with the sql for the other models in that app).

--
Ticket URL: <https://code.djangoproject.com/ticket/22775>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 6, 2014, 3:43:02 AM6/6/14
to django-...@googlegroups.com
#22775: Management command sqlall should support unmanaged models
-------------------------------------+-------------------------------------

Reporter: smeatonj | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: sqlall | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by loic84):

* cc: loic84 (added)
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/22775#comment:1>

Django

unread,
Jun 7, 2014, 2:42:59 PM6/7/14
to django-...@googlegroups.com
#22775: Management command sqlall should support unmanaged models
-------------------------------------+-------------------------------------
Reporter: smeatonj | Owner: nobody
Type: New feature | Status: closed

Component: Core (Management | Version: master
commands) | Resolution: wontfix

Severity: Normal | Triage Stage: Accepted
Keywords: sqlall | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by mardini):

* status: new => closed
* resolution: => wontfix


Comment:

After a discussion on IRC, Tim suggested closing this ticket and not doing
any new work on sql commands, since they will be deprecate according to
Andrew: https://code.djangoproject.com/ticket/22611#comment:6

--
Ticket URL: <https://code.djangoproject.com/ticket/22775#comment:2>

Django

unread,
Jun 8, 2014, 12:02:32 AM6/8/14
to django-...@googlegroups.com
#22775: Management command sqlall should support unmanaged models
-------------------------------------+-------------------------------------

Reporter: smeatonj | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) | Resolution:

Severity: Normal | Triage Stage: Accepted
Keywords: sqlall | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by loic84):

* cc: timo (added)
* status: closed => new
* resolution: wontfix =>


Comment:

@mardini, these commands going away doesn't change the fact that we don't
have an answer to the problem of generating SQL for unmanaged models.

I think the feature request still stands even if it'll have to go through
a different path than `sqlall`.

--
Ticket URL: <https://code.djangoproject.com/ticket/22775#comment:3>

Django

unread,
Jun 11, 2014, 1:43:55 PM6/11/14
to django-...@googlegroups.com
#22775: Management command sqlall should support unmanaged models
-------------------------------------+-------------------------------------

Reporter: smeatonj | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: sqlall | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by shai):

May I suggest a workaround:

1. Edit your app models, comment out the "managed=False" lines.
2. Use sqlall, save output.
3. Restore models.

Now you have a sql file you can use instead of manual labor.

Or, if you're terribly worried about forgetting to restore the models --

1. Start a new project. Direct it to a database that has the tables.
2. startapp
3. inspectdb
4. sqlall
5. Throw away the project.

This can even be done in a script, in case your unmanaged models change
and you need to re-do this often.

This one actually points in the direction of a possible solution -- it
could be a flag on the `inspectdb` command (`--sql` or some such).

--
Ticket URL: <https://code.djangoproject.com/ticket/22775#comment:4>

Django

unread,
Jun 11, 2014, 7:07:53 PM6/11/14
to django-...@googlegroups.com
#22775: Management command sqlall should support unmanaged models
-------------------------------------+-------------------------------------

Reporter: smeatonj | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: sqlall | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by smeatonj):

I don't think either of those workarounds are particularly good. We
discussed setting managed=False as a temporary solution, but that can be
cumbersome, and has to be repeated by every dev (unless you copy the
output to a new script..). Your second solution also requires devs to have
direct access to the production database, and possibly one that has a lot
more in it then a single table that you just want to output sql for.

For my specific use-case I have materialised views and views in the
production database (managed=False), but want to create tables that match
the definition in the development database. These definitions may change
over time, so `inspectdb --sql` isn't really what I'm after. And with the
sql commands going away, I'm not sure how switching the managed setting
temporarily is going to work with migrations.

--
Ticket URL: <https://code.djangoproject.com/ticket/22775#comment:5>

Django

unread,
Sep 15, 2022, 5:15:56 PM9/15/22
to django-...@googlegroups.com
#22775: Management command sqlall should support unmanaged models
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: nobody

Type: New feature | Status: new
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: sqlall | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Aman Pandey):

since sqlall has been deprecated , should we need to build a new command
or add the feature on existing one?

--
Ticket URL: <https://code.djangoproject.com/ticket/22775#comment:6>

Reply all
Reply to author
Forward
0 new messages