Obras para versiones superiores a Django 1,9
Primer paso: -Importe este (puede cambiar en versiones más recientes, por lo que vuelve a comprobar que)
from django.core.validators import validate_comma_separated_integer_list
Segundo Paso: -Campo de escritura
class RestaurantLocation(models.Model):
name = models.CharField(max_length=200)
location = models.CharField(max_length=200,null=True,blank=True)
category = models.CharField(max_length=200,null=True,blank=False)
choices_field = models.CharField(validators=[validate_comma_separated_integer_list],max_length=200, blank=True, null=True,default='')
def __str__(self):
return self.name
Nota: Por favor asegúrese de usar default = ''
si va a agregar columna a una base de datos ya creada otra forma podrías tener la siguiente opción de elegir después de ejecutar python manage.py migrate
You are trying to add a non-nullable field 'choices_field' to restaurantlocation without a default; we can't do that (the database needs something to populate existing rows).
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
Select an option:
feliz Codificación !
¿Sabe si el max_length correspondiente al campo incluye comas? – khalid13
sí, incluye como es una cadena. –