Hello Developers,
I’m facing a problem I’ve never encountered before. I’m still unsure whether it’s a Django-induced bug or an issue with the code I wrote. When I make changes to models.py
and run the expected commands, I get the message “No migrations to apply.” When I check via PGAdmin, migrations are not applied to the database. The makemigrations
command fails to properly detect changes and create migration files.
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, app
Running migrations:
No migrations to apply.
Due to confidentiality agreements, I can’t share much content, but we have had to reset the database many times due to this issue. It’s really frustrating. A similar problem was discussed in the forum before, but I couldn’t gather much data from the 2022 post.
Here is the models.py:
class Report(models.Model):
STATUS_CHOICES = (
("open", "Open"),
("close", "Close"),
)
PRIORITY_CHOICES = (
(1, "1"),
(2, "2"),
(3, "3"),
(4, "4"),
(5, "5"),
)
RISK_LEVEL_CHOICES = (
("low", "Low"),
("medium", "Medium"),
("high", "High"),
("critical", "Critical"),
)
title = models.CharField(max_length=255)
asset = models.CharField(max_length=255)
code = models.CharField(max_length=50)
priority = models.IntegerField(choices=PRIORITY_CHOICES)
risk_level = models.CharField(max_length=50, choices=RISK_LEVEL_CHOICES)
source = models.CharField(max_length=255)
analyst = models.ForeignKey(
User, on_delete=models.CASCADE, limit_choices_to={"role": "analyst"}
)
status = models.CharField(max_length=50, choices=STATUS_CHOICES)
description = models.TextField()
creation_date = models.DateTimeField(default=timezone.now)
modification_date = models.DateTimeField(auto_now=True)
confirmation = models.BooleanField(default=False)
class Meta:
indexes = [
models.Index(fields=['title']),
models.Index(fields=['creation_date']),
models.Index(fields=['priority']),
models.Index(fields=['risk_level']),
]
def __str__(self):
return self.title
I would appreciate any help or guidance on resolving this issue.