summaryrefslogtreecommitdiff
path: root/docs/howto
diff options
context:
space:
mode:
authorBaylee Feore <baylee@yeti.co>2016-06-02 17:50:11 -0700
committerTim Graham <timograham@gmail.com>2016-06-08 10:38:48 -0400
commit5e46075fcf5dce3a846d208ab39e7f7aed7f70eb (patch)
tree9ccc0143a3b5d6149e697126068d1e9a13150ef7 /docs/howto
parentb04e6ec7cba4abc566c28fcb44009d086d9629fb (diff)
[1.10.x] Fixed #26702 -- Documented how to change the base class of a custom field.
Backport of 7767978beec6098baea75d50a191a3b8224e729f from master
Diffstat (limited to 'docs/howto')
-rw-r--r--docs/howto/custom-model-fields.txt28
1 files changed, 28 insertions, 0 deletions
diff --git a/docs/howto/custom-model-fields.txt b/docs/howto/custom-model-fields.txt
index 1730419787..0c26d2ca5d 100644
--- a/docs/howto/custom-model-fields.txt
+++ b/docs/howto/custom-model-fields.txt
@@ -311,6 +311,34 @@ and reconstructing the field::
new_instance = MyField(*args, **kwargs)
self.assertEqual(my_field_instance.some_attribute, new_instance.some_attribute)
+Changing a custom field's base class
+------------------------------------
+
+You can't change the base class of a custom field because Django won't detect
+the change and make a migration for it. For example, if you start with::
+
+ class CustomCharField(models.CharField):
+ ...
+
+and then decide that you want to use ``TextField`` instead, you can't change
+the subclass like this::
+
+ class CustomCharField(models.TextField):
+ ...
+
+Instead, you must create a new custom field class and update your models to
+reference it::
+
+ class CustomCharField(models.CharField):
+ ...
+
+ class CustomTextField(models.TextField):
+ ...
+
+As discussed in :ref:`removing fields <migrations-removing-model-fields>`, you
+must retain the original ``CustomCharField`` class as long as you have
+migrations that reference it.
+
Documenting your custom field
-----------------------------