I'm using a PostgreSQL database hosted with aws, everytime I try to migrate (python manage.py migrate
) I run into this error: column "id" referenced in foreign key constraint does not exist
.
I have tried removing the two foreign keys that I'm using with no luck I still get the same error. I have also tried this solution with no luck. The rest migrates with no problem, Just this one error
Model.py
class Subprogram(models.Model):
title = models.CharField(max_length=100)
program = models.ForeignKey(Program, on_delete=models.CASCADE)
budget = models.DecimalField(default=0, decimal_places=0, max_digits=11)
class Project(models.Model):
name = models.CharField(max_length=100)
budget = models.DecimalField(decimal_places=0, max_digits=11)
budget_year = models.PositiveIntegerField(default=current_year(), validators=[MinValueValidator(current_year)])
file = models.FileField(blank=True)
subprogram = models.ForeignKey(Subprogram, on_delete=models.CASCADE)
class Program(models.Model):
title = models.CharField(max_length=100)
date_posted = models.DateTimeField(default=timezone.now)
def overall_budget(self):
all_projects = self.subprogram_set.all()
total = 0
for project in all_projects:
total += project.budget
return total
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('program-detail', kwargs={'pk': self.pk})
question from:
https://stackoverflow.com/questions/65865627/django-postgres-migration-error-foreign-key-constraint-does-not-exist 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…