[Django] #24481: Allow use of sql* commands even on apps with migrations

10 views
Skip to first unread message

Django

unread,
Mar 14, 2015, 5:11:47 AM3/14/15
to django-...@googlegroups.com
#24481: Allow use of sql* commands even on apps with migrations
-------------------------------------+-------------------------------------
Reporter: pakal | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.7
commands) | Keywords: migrate migrations
Severity: Normal | sqlall
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
When upgrading a django+djangocms install to latest versions, things got
broken (at least one sql table with missing, even though MIGRATION_MODULES
was well filled and "manage.py migrate" indicated all was up-to-date).

I wanted to use sqlall and other commands to diff my existing DB with the
"theoretical" one, but django refused, indicating that only sqlmigrate and
sqlflush were allowed for apps with migrations. I had to redeploy another
install from scratch to do the diff.

Wouldn't it be better to issue a warning in these cases, but let the
developper use these tools to understand what's wrong, and manually "fake"
migrations when stuffs are out of control ?

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

Django

unread,
Mar 14, 2015, 9:40:11 AM3/14/15
to django-...@googlegroups.com
#24481: Allow use of sql* commands even on apps with migrations
-------------------------------------+-------------------------------------
Reporter: pakal | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.7
commands) |
Severity: Normal | Resolution:
Keywords: migrate migrations | Triage Stage:
sqlall | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

I think those commands can't work like they did before because when there
are multiple migrations, I don't think it's feasible to determine what the
resulting database schema will look like.

Maybe an idea would be to make the `migration_name` argument to
`sqlmigrate` optional so that you could do `sqlmigrate <app_name>` to get
the SQL for all of your migrations in an app. I guess we might be able to
make `app_name` optional as well so that `sqlmigrate` could easily output
the SQL for all migrations of all apps.

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

Django

unread,
Mar 15, 2015, 10:23:17 AM3/15/15
to django-...@googlegroups.com
#24481: Allow use of sql* commands even on apps with migrations
-------------------------------------+-------------------------------------
Reporter: pakal | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.7
commands) |
Severity: Normal | Resolution:
Keywords: migrate migrations | Triage Stage:
sqlall | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by pakal):

Do you mean "sqlmigrate" would output, in sequence, all "alter tables"
commands to recreate the final DBs ?

I've had a look at django\core\management\sql.py, a function
check_for_migrations() is called to abort when some models use migrations,
but other than that, nothing seems to prevent generation from sql for
migration-enabled models. There is even, farther, code which looks
explicitely dedicated to migration handling ("for model in
router.get_migratable_models(app_config, connection.alias,
include_auto_created=True)").

From what I understand, these sql* commands browse '''current''' model
objects, and convert them to sql statements, so I guess they shouldn't
care about whether these python classes have some "history" behind them.
Or am I misunderstanding how all that works ?

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

Django

unread,
Mar 17, 2015, 9:41:40 AM3/17/15
to django-...@googlegroups.com
#24481: Allow use of sql* commands even on apps with migrations
-------------------------------------+-------------------------------------
Reporter: pakal | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: migrate migrations | Triage Stage: Accepted
sqlall |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* version: 1.7 => master
* type: Bug => New feature
* stage: Unreviewed => Accepted


Comment:

It might work. Would be happy to look at a patch but might have to close
this if it ends up being confusing or not feasible to implement.

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

Django

unread,
Mar 20, 2015, 7:52:13 AM3/20/15
to django-...@googlegroups.com
#24481: Allow use of sql* commands even on apps with migrations
-------------------------------------+-------------------------------------
Reporter: pakal | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: migrate migrations | Triage Stage: Accepted
sqlall |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by pakal):

Looked at the master-branch code, all the code for these commands has
disappeared from it, however it'd really be worth to resurrect the
"sqlcreate" command only, it's invaluable for quick debugging of migration
troubles.

I'll start a thread on the mailing-list to see what's the status about all
this.

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

Django

unread,
Mar 22, 2015, 9:43:12 AM3/22/15
to django-...@googlegroups.com
#24481: Allow use of sql* commands even on apps with migrations
-------------------------------------+-------------------------------------
Reporter: pakal | Owner: raulcd
Type: New feature | Status: assigned

Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: migrate migrations | Triage Stage: Accepted
sqlall |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by raulcd):

* status: new => assigned
* owner: nobody => raulcd


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

Django

unread,
Mar 22, 2015, 10:07:12 AM3/22/15
to django-...@googlegroups.com
#24481: Allow use of sql* commands even on apps with migrations
-------------------------------------+-------------------------------------
Reporter: pakal | Owner: raulcd
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: migrate migrations | Triage Stage: Accepted
sqlall |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by raulcd):

* has_patch: 0 => 1


Comment:

PR at:
https://github.com/django/django/pull/4374

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

Django

unread,
Mar 22, 2015, 11:57:38 AM3/22/15
to django-...@googlegroups.com
#24481: Allow use of sql* commands even on apps with migrations
-------------------------------------+-------------------------------------
Reporter: pakal | Owner:
Type: New feature | Status: new

Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: migrate migrations | Triage Stage: Accepted
sqlall |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by raulcd):

* status: assigned => new
* owner: raulcd =>
* has_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/24481#comment:7>

Django

unread,
Jun 1, 2015, 11:37:02 AM6/1/15
to django-...@googlegroups.com
#24481: Allow use of sql* commands even on apps with migrations
-------------------------------------+-------------------------------------
Reporter: pakal | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: migrate migrations | Triage Stage: Accepted
sqlall |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by andrewgodwin):

I've started working on this here:
https://github.com/django/django/pull/4729

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

Django

unread,
Jun 3, 2015, 7:43:27 AM6/3/15
to django-...@googlegroups.com
#24481: Improve sqlmigrate to be more flexible and allow bypassing migrations on
disk

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

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

Comment (by MarkusH):

Andrew, Loic, Florian and I came up with the following list of features we
want `sqlmigrate` to support:

* just one migration
* list of migration names
* start / end of migration graph
* ignore migrations and build straight from models

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

Django

unread,
Jun 3, 2015, 7:44:45 AM6/3/15
to django-...@googlegroups.com
#24481: Improve sqlmigrate to be more flexible and allow bypassing migrations on
disk
-------------------------------------+-------------------------------------
Reporter: pakal | Owner:
| andrewgodwin

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

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by MarkusH):

* owner: nobody => andrewgodwin


--
Ticket URL: <https://code.djangoproject.com/ticket/24481#comment:7>

Django

unread,
Jun 3, 2015, 7:45:16 AM6/3/15
to django-...@googlegroups.com
#24481: Improve sqlmigrate to be more flexible and allow bypassing migrations on
disk
-------------------------------------+-------------------------------------
Reporter: pakal | Owner:
| andrewgodwin
Type: New feature | Status: assigned

Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: migrate migrations | Triage Stage: Accepted
sqlall |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by andrewgodwin):

* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/24481#comment:8>

Django

unread,
Mar 5, 2022, 6:22:15 AM3/5/22
to django-...@googlegroups.com
#24481: Improve sqlmigrate to be more flexible and allow bypassing migrations on
disk
-------------------------------------+-------------------------------------
Reporter: pascal chambon | Owner: (none)
Type: New feature | Status: new
Component: Core (Management | Version: dev

commands) |
Severity: Normal | Resolution:
Keywords: migrate migrations | Triage Stage: Accepted
sqlall |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: Andrew Godwin => (none)


* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/24481#comment:9>

Reply all
Reply to author
Forward
0 new messages