django.db.utils.OperationalError: no such table: polls_post

Viewed 483

I'm looking at this problem for an hour but i cannot find what's wrong with this, when I run python manage.py shell and import like from polls.models import Post and call on the shell Post.objects.all() it shows an error like this "django.db.utils.OperationalError: no such table: polls_post"

How can I solve this ?

This is the polls.models.py

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User

class Post(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    date_posted = models.DateTimeField(default=timezone.now)
    author = models.ForeignKey(User, on_delete=models.CASCADE)

This is the 0001_initial.py

# Generated by Django 3.1 on 2020-08-31 02:53


from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Post',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=200)),
                ('content', models.TextField()),
                ('date_posted', models.DateTimeField(default=django.utils.timezone.now)),
                ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
    ]
1 Answers

You should run migrate command, which is responsible for applying and unapplying migrations.

Related