this is my model
class Prestamo(models.Model): lector = models.ForeignKey( Lector, on_delete=models.CASCADE) libro = models.ForeignKey(Libro, on_delete=models.CASCADE , related_name='libro_prestamo') fecha_prestamo = models.DateField() fecha_devolucion = models.DateField(blank=True, null=True) devuelto = models.BooleanField()
and this is my error in console
return self.cursor.execute(sql, params) django.db.utils.IntegrityError: inserción o actualización en la tabla «lector_prestamo» viola la llave foránea «lector_prestamo_libro_id_c94b640a_fk_libro_libro_id» DETAIL: La llave (libro_id)=(0) no está presente en la tabla «libro_libro».
i dont know how to solve it
CodePudding user response:
Try deleting/removing your db.sqlite3
file and all your migration files in migration folder
then run python manage.py makemigrations
followed by python manage.py migrate