[Python] A problem occurs when adding a new foreign key field to a model

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    So, I added a foreign key field to my model, ran "makemigrations" and "migrate" without problems, but when I check my database via DB browser, I cannot find that field!

    This is my model

    class Listing (models.Model):
    CATEGORY_CHOICES = [
    ("chemistry", "Chemistry"),
    ("physics", "Physics"),
    ("math", "Math"),
    ("litreture", "Litreture"),
    ("history", "History"),
    ("language", "Language"),
    ("sports", "Sports")
    ]
    title = models.CharField(max_length=80)
    brief = models.CharField(max_length=128)
    description = models.TextField()
    intial_price = models.IntegerField()
    category = models.CharField(max_length=24, choices=CATEGORY_CHOICES)

    # The problem is within the line below
    creator = models.ForeignKey(User, on_delete=models.CASCADE, related_name='listings')
    # I cannot find this field in my database file when browsing it via DB browser
    def __str__(self):
    return self.title


    I tried to ask the AI a lot but all it said was to check the migrations files and make sure the migration process is successful. I am sure that there is no issue with those two. I ran out of ideas, help!

    Continue reading...

Compartilhe esta Página