#30795: Django cannot serialize value into migration file
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  SebaRossi94                        |
                   Type:  Bug        |         Status:  new
              Component:  Core       |        Version:  2.2
  (Serialization)                    |       Keywords:  Serialize,
               Severity:  Normal     |  makemigrations, migrate
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Hi there i'm having problems when trying to use the command makemigrations
 with manage.py. The output is the following:
 {{{
 Migrations for 'reg':
   reg\migrations\0012_auto_20190917_1711.py
     - Remove field Products from tenant
     - Add field products to tenant
     - Alter field productos on preaprobado
     - Alter field tenant_id on preaprobado
     - Alter field CMS_id on producto
     - Alter field CMS_id on tenant
 }}}

 **Traceback errors**

 {{{
 ValueError: Cannot serialize: <Producto: Basico - ['IPTEL', 'Rocstar',
 'Test_DVT']>
     There are some values Django cannot serialize into migration files.
     For more, see https://docs.djangoproject.com/en/2.2/topics/migrations
 /#migration-serializing
 }}}

 The thing is that the entire app works just fine but for some reason i
 can't understand i cannot migrate the db.

 Here is the models.py:

 {{{
 class Tenant(models.Model):
     Name = models.CharField(max_length = 30, unique = True)
     Enabled = models.BooleanField(default = False)
     CMS_id = models.PositiveIntegerField(unique = True)
     Logo = models.ImageField(upload_to = "Logos/", blank = True)
     Icon = models.ImageField(upload_to = "Icons/", blank = True)
     Domain = models.URLField(default = "http://localhost:8000";)
     Master = models.BooleanField(default = False)
     products = models.ManyToManyField(Producto, related_name = "tenants")

     def __str__(self):
         return(self.Name)

 # Override del metodo que salva en la db para que si se quiere salvar un
 Tenant con Master = True y
 # existe un Tenant con mismo dominio y Master = True no pueda salvar
     def save(self, *args, **kwargs):
         #busca tenant con mismo dominio y Master = True
         try:
             master_tenant = Tenant.objects.filter(Domain =
 self.Domain).get(Master = True)
             #Si el tenant encontrado es el que se quiere salvar chequeo
 que sea Master = True y salvo
             #sino pido Master = True. Chequea tambien que el master tenga
 logo e icono si o si
             if master_tenant.id == self.id:
                 if self.Master:
                     if self.Logo != "" and self.Icon != "":
                         super(Tenant, self).save(*args, **kwargs)
                     else:
                         raise ValidationError({"Logo" : "Logo required",
 "Icon" : "Icon rquired"})
                 else:
                     raise ValidationError({"Master" : "At least one Master
 per Domain"})
             else:
                 #Si no es el Master = True del dominio y Master = False
 guarda, sino error
                 if self.Master:
                     if self.Logo != "" and self.Icon != "":
                         super(Tenant, self).save(*args, **kwargs)
                     else:
                         raise ValidationError({"Logo" : "Logo required",
 "Icon" : "Icon rquired"})
                 else:
                     super(Tenant, self).save(*args, **kwargs)

         #Si no existe tenant con mismo Domain y Master = True, Se fija que
 Master = True y que tenga logo e icono y salva, sino, error
         except Tenant.DoesNotExist:
             if self.Master:
                 if self.Logo != "" and self.Icon != "":
                     super(Tenant, self).save(*args, **kwargs)
                 else:
                     raise ValidationError({"Logo" : "Logo required",
 "Icon" : "Icon rquired"})
             else:
                 raise ValidationError({"Master" : "At least one Master per
 Domain"})


 class Preaprobado(models.Model):
     codigo = models.CharField(max_length = 100)
     tenant_id = models.ForeignKey(Tenant, on_delete = models.CASCADE,
 related_name = "tenant")
     can_register = models.BooleanField(default = True)
     is_registered = models.BooleanField(default = False)
     productos = models.ManyToManyField(Producto, related_name =
 "preaprobados", default = Producto.objects.get(id = 1))

     def __str__(self):
         return(self.codigo + "-" + self.tenant_id.Name)



     class Meta():
         #No permite un par codigo-tenant repetido dentro del modelo
 Preaprobado
         constraints = [
         models.UniqueConstraint(fields = ["codigo", "tenant_id"], name =
 "par código-Tenant únicos"),
         ]
 }}}

 Any help is welcomed since i actually can't find what is wrong with the
 code. Not even in the documentation. I'm new with Django so maybe the
 solution is pretty easy but i can't find it.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30795>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/054.47d878c0f3f889f2ec3e77e9d6daa86d%40djangoproject.com.

Reply via email to