Error when adding a text with Django 3, how to fix it?

Asked

Viewed 32 times

0

from django.db import models


class Topic(models.Model):
    text = models.CharField(max_length=200)
    date_added = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.text


class Entry(models.Model):
    topic = models.ForeignKey(Topic, on_delete=models.PROTECT)
    text = models.TextField()
    date_added = models.DateTimeField(auto_now_add=True)

    class Meta:
        verbose_name_plural = 'entries'

    def __str__(self):
        return self.text[:50] + "..."

For me it was okay I had my template that made the user write a topic and he could put a subject related to it as in the image of my admin page to follow:

Minha pagina de admin But when saving my text there was an error that I don’t understand why...

Traceback

Can you help me?

  • Does not print the error, but the message.

  • You didn’t create Migration... python manage.py makemigrations afterward python manage.py migrate

  • created yes...it even made a file in Migrations folder:

1 answer

0

Oops I already found the solution!

in:

text = models.TextField()

the database does not create a table named text but if we put:

text = models.TextField(auto_created=True)

and migrate again works...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.