【发布时间】:2021-04-22 08:35:19
【问题描述】:
这是我得到的错误。
django.db.utils.OperationalError:没有这样的表:photos_post_likes
我关注这个视频是为了创建一个赞按钮。 https://youtu.be/pkPRtQf6oQ8
那时我已经创建了模型(帖子)。就在我在 models.py 中添加新行(喜欢)并运行 makemigrations 时,它迁移没有任何问题。但是,当我运行迁移时,出现了这个错误。
这是models.py文件
from django.db import models
from django.utils import timezone
from django.urls import reverse
from django.contrib.auth.models import User
from PIL import Image
class Post(models.Model):
date_shared = models.DateTimeField(default=timezone.now)
caption = models.TextField(max_length=50)
user = models.ForeignKey(User, on_delete=models.CASCADE)
likes = models.ManyToManyField(User, blank=True, related_name='post_likes') # this line made the error occur
image = models.ImageField(upload_to='post_images')
def __str__(self):
return self.caption
def save(self):
super().save()
img = Image.open(self.image.path)
if img.height > 800 or img.width > 800:
output_size = (800, 800)
img.thumbnail(output_size)
img.save(self.image.path)
def get_absolute_url(self):
return reverse('home')
【问题讨论】:
标签: python django django-models