Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
Do I need to make a migration if I change null and blank values on a Model field?

I have the following model

@python_2_unicode_compatible
class Booking(models.Model):
    session = models.ForeignKey(verbose_name=_('Session'), to=Session, default=None, null=False, blank=False)
    quantity = models.PositiveIntegerField(verbose_name=_('Quantity'), default=1, null=False, blank=False)
    price = models.DecimalField(verbose_name=_('Price'), max_digits=10, decimal_places=2,
                                default=None, null=False, blank=False)
    name = models.CharField(verbose_name=_('Name'), max_length=100, default=None, null=False, blank=False)
    email = models.EmailField(verbose_name=_('Email'), default=None, null=True, blank=True)
    phone_number = models.CharField(verbose_name=_('Phone Number'), max_length=30, default=None, null=True, blank=True)

Say I need to change my email and phone_number fields. I want them to have null=False and blank=False. Do these alterations require a new migration?

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Yes they do. null=False requires a change to the database schema itself; blank=False does not, but Django needs a migration anyway so that the migration runner's internal graph of the model state is up to date.

about 4 years ago · Santiago Trujillo Relatório

0

Sure. To check it you can run python manage.py makemigrations --dry-run (the --dry-run doesn't save a new migration file, but shows if it's necessary)

about 4 years ago · Santiago Trujillo Relatório

0

https://docs.djangoproject.com/en/1.11/topics/db/models/#field-options

Django document says:

null

If True, Django will store empty values as NULL in the database. Default >is False.

blank

If True, the field is allowed to be blank. Default is False.

Note that this is different than null. null is purely database-related, whereas blank is validation-related. If a field has blank=True, form validation will allow entry of an empty value. If a field has blank=False, the field will be required.

For change in null you need to migrate

For change in blank you need not to migrate, because its admin form related

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda