1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #31468 -- Allowed specifying migration filename in Operation.

This adds also suggested filename for many built-in operations.
This commit is contained in:
Adam Johnson
2019-11-23 11:08:45 +00:00
committed by Mariusz Felisiak
parent 5bd585a82d
commit fa58450a9a
10 changed files with 149 additions and 13 deletions

View File

@@ -484,6 +484,16 @@ structure of an ``Operation`` looks like this::
# This is used to describe what the operation does in console output.
return "Custom Operation"
@property
def migration_name_fragment(self):
# Optional. A filename part suitable for automatically naming a
# migration containing this operation, or None if not applicable.
return "custom_operation_%s_%s" % (self.arg1, self.arg2)
.. versionadded:: 3.2
The ``migration_name_fragment`` property was added.
You can take this template and work from it, though we suggest looking at the
built-in Django operations in ``django.db.migrations.operations`` - they cover
a lot of the example usage of semi-internal aspects of the migration framework
@@ -553,3 +563,7 @@ state changes, all it does is run one command::
def describe(self):
return "Creates extension %s" % self.name
@property
def migration_name_fragment(self):
return "create_extension_%s" % self.name

View File

@@ -171,7 +171,9 @@ Management Commands
Migrations
~~~~~~~~~~
* ...
* The new ``Operation.migration_name_fragment`` property allows providing a
filename fragment that will be used to name a migration containing only that
operation.
Models
~~~~~~