Why does Django make migrations for help_text and verbose_name changes?

后端 未结 8 2273
情深已故
情深已故 2020-12-15 15:00

When I change help_text or verbose_name for any of my model fields and run python manage.py makemigrations, it detects these changes a

8条回答
  •  無奈伤痛
    2020-12-15 15:41

    You can squash it with the previous migration, sure.

    Or if you don't want to output those migrations at all, you can override the makemigrations and migrate command by putting this in management/commands/makemigrations.py in your app:

    from django.core.management.commands.makemigrations import Command
    from django.db import models
    
    IGNORED_ATTRS = ['verbose_name', 'help_text', 'choices']
    
    original_deconstruct = models.Field.deconstruct
    
    def new_deconstruct(self):
      name, path, args, kwargs = original_deconstruct(self)
      for attr in IGNORED_ATTRS:
        kwargs.pop(attr, None)
      return name, path, args, kwargs
    
    models.Field.deconstruct = new_deconstruct
    

提交回复
热议问题