Opened 9 years ago

Closed 2 years ago

#24870 closed New feature (fixed)

Create --update flag for makemigrations management command, mimicking South's one.

Reported by: Israel Saeta Pérez Owned by: David Wobrock
Component: Migrations Version: dev
Severity: Normal Keywords: migrations, south
Cc: David Wobrock Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When I was developing with South I was able to use the --update flag for the schemamigration management command (http://south.readthedocs.org/en/latest/commands.html#schemamigration) to refine the latest migration.

This was very convenient for iterative development. Could we have an equivalent of the --update flag for Django>=1.7 makemigrations?

(I've taken it from http://stackoverflow.com/questions/30487909/what-is-the-equivalent-of-souths-schemamigration-update-for-django-1-7)

Change History (14)

comment:1 by Tim Graham, 9 years ago

Cc: Andrew Godwin added

Andrew, could you offer your view.

comment:2 by Andrew Godwin, 9 years ago

It's certainly possible, though more complicated than before in South because of the multi-app nature of makemigrations - but also easier because of the ease of programatically parsing and writing migration files.

What this would be, in essence, is something that runs makemigrations and glues the first migration it makes for each app to the most recent one that already exists. The pain points I forsee are:

  • Migration files that have custom code (RunPython especially, but also any non-standard operation class) cannot be round-tripped through the parser and then out through the writer, so they could not be appended onto.
  • Dependencies would have to be checked to make sure this merging of the new migrations into old does not cause dependency loops.
  • It will occasionally have to just make new migrations anyway - it's more asking for a "best effort" attempt to make things work.

That said, I think it's not too complicated, and shares enough of these challenges with squashing (it's basically squashing the new migrations makemigrations creates into the last ones of the existing set), that we should aim to do it at some point.

comment:3 by Tim Graham, 9 years ago

Cc: Andrew Godwin removed
Triage Stage: UnreviewedAccepted

comment:4 by Markus Holtermann, 9 years ago

Version: 1.8master

comment:5 by David Wobrock, 3 years ago

Cc: David Wobrock added
Has patch: set
Owner: changed from nobody to David Wobrock
Status: newassigned

Hello,

I tried to tackle this ticket as I believe it would still be a pretty useful addition to makemigrations.
During development, I often see developers struggle with the manual steps to re-generate a migration while they are still iterating on their approach.

Here is the approach I've taken https://github.com/django/django/pull/15669
I tried to keep the implementation rather straightforward.

The main drawback I see is that it will add a new edge case when one updates a migration that has already been applied. This will create a bit of confusion, as it will become more tedious to undo the updated migration, since the reverse operations will try to undo things that weren't initially applied.

comment:6 by Mariusz Felisiak, 2 years ago

Patch needs improvement: set

comment:7 by David Wobrock, 2 years ago

Patch needs improvement: unset

comment:8 by Mariusz Felisiak, 2 years ago

Needs tests: set
Patch needs improvement: set

comment:9 by David Wobrock, 2 years ago

Needs tests: unset
Patch needs improvement: unset

comment:10 by Mariusz Felisiak, 2 years ago

Patch needs improvement: set

comment:11 by David Wobrock, 2 years ago

Patch needs improvement: unset

comment:12 by Mariusz Felisiak, 2 years ago

Triage Stage: AcceptedReady for checkin

comment:13 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

In 3893fcdd:

Refs #24870 -- Refactored out get_relative_path() hook in makemigrations.

comment:14 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In e286ce17:

Fixed #24870 -- Added --update option to makemigrations command.

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