[英]django.db.utils.OperationalError: no such table: polls_post
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"
我正在研究这个问题一个小时,但是当我运行
python manage.py shell
并像from polls.models import Post
一样from polls.models import Post
并调用它显示的 shell Post.objects.all()
时,我找不到这有什么问题像这样的错误"django.db.utils.OperationalError: no such table: polls_post"
How can I solve this ?我该如何解决这个问题?
This is the polls.models.py
这是
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
这是
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)),
],
),
]
您应该运行migrate命令,该命令负责应用和取消应用迁移。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.