0

Al crear nuevo modelo, me devuelve el siguiente error. Es como si tuvieran incompatibilidad de nombres, pero los nombre de los campos son diferentes. ¿Qué puede ocurrir? Gracias.

Error:

SystemCheckError: System check identified some issues:

ERRORS:
repair.Repair.affectedDevice_repair: (fields.E304) Reverse accessor for 'Repair.affectedDevice_repair' clashes with reverse accessor for 'Repair.placedDevice_repair'.
        HINT: Add or change a related_name argument to the definition for 'Repair.affectedDevice_repair' or 'Repair.placedDevice_repair'.
repair.Repair.affectedDevice_repair: (fields.E304) Reverse accessor for 'Repair.affectedDevice_repair' clashes with reverse accessor for 'Repair.removedDevice_repair'.
        HINT: Add or change a related_name argument to the definition for 'Repair.affectedDevice_repair' or 'Repair.removedDevice_repair'.
repair.Repair.placedConsumable_repair: (fields.E304) Reverse accessor for 'Repair.placedConsumable_repair' clashes with reverse accessor for 'Repair.removedConsumable_repair'.
        HINT: Add or change a related_name argument to the definition for 'Repair.placedConsumable_repair' or 'Repair.removedConsumable_repair'.
repair.Repair.placedDevice_repair: (fields.E304) Reverse accessor for 'Repair.placedDevice_repair' clashes with reverse accessor for 'Repair.affectedDevice_repair'.
        HINT: Add or change a related_name argument to the definition for 'Repair.placedDevice_repair' or 'Repair.affectedDevice_repair'.
repair.Repair.placedDevice_repair: (fields.E304) Reverse accessor for 'Repair.placedDevice_repair' clashes with reverse accessor for 'Repair.removedDevice_repair'.
        HINT: Add or change a related_name argument to the definition for 'Repair.placedDevice_repair' or 'Repair.removedDevice_repair'.
repair.Repair.removedConsumable_repair: (fields.E304) Reverse accessor for 'Repair.removedConsumable_repair' clashes with reverse accessor for 'Repair.placedConsumable_repair'.
        HINT: Add or change a related_name argument to the definition for 'Repair.removedConsumable_repair' or 'Repair.placedConsumable_repair'.
repair.Repair.removedDevice_repair: (fields.E304) Reverse accessor for 'Repair.removedDevice_repair' clashes with reverse accessor for 'Repair.affectedDevice_repair'.
        HINT: Add or change a related_name argument to the definition for 'Repair.removedDevice_repair' or 'Repair.affectedDevice_repair'.
repair.Repair.removedDevice_repair: (fields.E304) Reverse accessor for 'Repair.removedDevice_repair' clashes with reverse accessor for 'Repair.placedDevice_repair'.
        HINT: Add or change a related_name argument to the definition for 'Repair.removedDevice_repair' or 'Repair.placedDevice_repair'.

Archivo models.py

class Repair(models.Model):
    datetime_repair = models.DateTimeField ('Fecha actuación',null=True, blank=True)
    incidence_repair = models.ForeignKey(Incidence, on_delete=models.CASCADE,null=True, blank=True)
    affectedDevice_repair = models.ForeignKey(Device, on_delete=models.CASCADE,null=True, blank=True)
    typeFailure_repair = models.ForeignKey(TypeFailure, on_delete=models.CASCADE,null=True, blank=True)
    typeRepair_repair = models.ForeignKey(TypeRepair, on_delete=models.CASCADE,null=True, blank=True)
    removedDevice_repair = models.ForeignKey(Device, on_delete=models.CASCADE,null=True, blank=True)
    placedDevice_repair = models.ForeignKey(Device, on_delete=models.CASCADE,null=True, blank=True)
    removedConsumable_repair = models.ForeignKey(Consumable, on_delete=models.CASCADE,null=True, blank=True)
    placedConsumable_repair = models.ForeignKey(Consumable, on_delete=models.CASCADE,null=True, blank=True)
    statusAfterRepair_repair = models.ForeignKey(StatusAfterRepair, on_delete=models.CASCADE,null=True, blank=True)
    summary_repair = models.TextField('Resumen',null=True, blank=True)
    detail_repair = models.TextField('Detalles',null=True, blank=True)

1 respuesta 1

4

Si tienes varios ForeignKey a una misma tabla, debes agregarle un related_name diferente a cada uno, de lo contrario, adopta por defecto el mismo related_name para todos y te da ese error. Por ejemplo:

affectedDevice_repair = models.ForeignKey(Device, on_delete=models.CASCADE,null=True, blank=True,related_name='affectedDevice_repair')
placedDevice_repair = models.ForeignKey(Device, on_delete=models.CASCADE,null=True, blank=True,related_name='placedDevice_repair')

Ahora debes hacerle eso a todos los campos de la tabla Repair con ForeignKey de las tablas Device y Consumable.

1
  • Ok! Y qué sentido tiene eso. En un ManyToMany entiendo que se crea tabla intermedia y necesita un nombre seguramente, pero en el caso de ForeignKey ¿Por qué nombrarla? Gracias Firefly!
    – ret
    Commented el 24 ago. 2020 a las 22:57

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.