I am trying to update new fields in my database about my "card" model, which already had the fields above, but I have a problem that prevents me from doing this process:
When I started. /manage.py syncdb, I received this message:
Your models have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
So, I ran the makemigrations command, but ...
You are trying to add a non-nullable field 'imagen' to card 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)
2) Quit, and let me add a default in models.py
I chose to click the second option and add this requirement myself, in fact I have this:
models.py:
from django.db import models
class subscriber(models.Model):
nombre = models.CharField(max_length=200)
apellidos = models.CharField(max_length=200)
status = models.BooleanField(default=True)
def __unicode__(self):
nombreCompleto = "%s %s"%(self.nombre,self.apellidos)
return nombreCompleto
def url(self,filename):
ruta = "MultimediaData/Card/%s/%s"%(self.nombre,str(filename))
return ruta
class card(models.Model):
nombre = models.CharField(max_length=100)
descripcion = models.TextField(max_length=300)
status = models.BooleanField(default=True)
imagen = models.ImageField(upload_to=url)
precio = models.DecimalField(max_digits=6,decimal_places=2)
stock = models.IntegerField()
def __unicode__(self):
return self.nombre
If I change the "Imagen" field as the message said, I would do the following:
imagen = models.ImageField (upload_to = url, default = '')
But then the same message appears after making the same modification in the "imagen" field:
You are trying to add a non-nullable field 'precio' to card without a default;
we can't do that (the database needs something to populate existing rows).
Please select a fix:
And finally, the last:
You are trying to add a non-nullable field 'stock' to card without a default;
we can't do that (the database needs something to populate existing rows).
Please select a fix:
If I change all of these fields, I can finally run. /manage.py makemigrations:
Migrations for 'synopticup':
0002_auto_20141016_2004.py:
- Add field imagen to card
- Add field precio to card
- Add field stock to card
. /manage.py syncdb, :
django.core.exceptions.ValidationError: [u"'' value must be a decimal number."]
? , :
class card(models.Model):
nombre = models.CharField(max_length=100)
descripcion = models.TextField(max_length=300)
status = models.BooleanField(default=True)
imagen = models.ImageField(upload_to=url)
precio = models.DecimalField(max_digits=6,decimal_places=2)
stock = models.IntegerField()
apologizeme , -.
!!