Opened 6 years ago

Closed 6 years ago

#29720 closed New feature (invalid)

Validating migrations using manage.py

Reported by: Thomas Basche Owned by: nobody
Component: Migrations Version: 2.1
Severity: Normal Keywords: migrations, manage.py, validation
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

At work we have several Django services each with several apps. Usually after a few devs merge pull requests into the main branch in Git we get migrations with the same number. From time to time there's also some reordering with dependencies in migrations leap-frogging the previous one.

This obviously gets picked up at run time, but it would be cool to be able to determine this at build time. Obviously we should all take more care, but I would consider this more of a "linting" stage than anything else.

In the interim I wrote (or rather, hacked together) a cli tool that validates this, but ultimately this would be better suited as a manage.py command. Something like manage.py validate-migrations . All it has to do is check the migration numbers are incremental and that their dependencies refer to the previous migration in the list.

Change History (2)

comment:1 by Tim Graham, 6 years ago

It's not clear to me what you're proposing. If I understand the scenario you're describing, you'll get an error if you run makemigrations --check. Is that insufficient?

$ python manage.py makemigrations --check
CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0002_auto_201808429_2051, 0002_auto_20180829_2051 in polls).
To fix them run 'python manage.py makemigrations --merge'

in reply to:  1 comment:2 by Thomas Basche, 6 years ago

Resolution: invalid
Status: newclosed

Replying to Tim Graham:

It's not clear to me what you're proposing. If I understand the scenario you're describing, you'll get an error if you run makemigrations --check. Is that insufficient?

$ python manage.py makemigrations --check
CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0002_auto_201808429_2051, 0002_auto_20180829_2051 in polls).
To fix them run 'python manage.py makemigrations --merge'

That is probably actually bang on. Cheers! Perhaps I should have read the documentation a bit closer...

Note: See TracTickets for help on using tickets.
Back to Top