Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

470
Vistas
I'm getting an error message when making migration to db in django

hello guys I'm doing a django tutorial and i missed a change the instructor did in models.py so i fix it but when trying to make the migration to the db it gives me a code that I don't understand or i don't know what to do, here is what it says:

(tonyto) PS E:\web-dev\Python\Django1\myappito> python manage.py makemigrations

Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit, and let me add a default in models.py

they way it was name: models.CharField(max_length=100) details: models.CharField(max_length=500)

and this is how i update it name: models.CharField(max_length=100) details: models.CharField(max_length=500) thank you in advance.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

first approach

  • this comes because you run the migration on each field created so the previous created filled doesn't accept null value so you want to provide default value in your case it is string value
  • you can choose the first choice and but the answer to be "default" with a quotation to understand it as a string

The second solution

delete the latest file created in the migration folder and modify your model to be

'''
name = models.CharField(max_length=100,null=True) 
details = models.CharField(max_length=500, null=True) 
'''

then run the migration again

python manage.py makemigration python manage.py migrate then go back to model again and remove null from each field and run python manage.py makemigration python manage.py migrate

over 4 years ago · Santiago Trujillo Denunciar

0

This was caused because you're trying to migrate a model field that cannot be null, but since it cannot be null, it needs a default value so that django can replace all the existing rows with the null value of that field.

You have two options:

  1. Provide the default by hand, and the django it's going to replace all the null values of that field with this

  2. Set a default value in the model, example:

number = models.IntegerField(default=1)

string = models.CharField(default='')

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda