This is the error that I got.
django.db.utils.OperationalError: no such table: photos_post_likes
I was following this video to create a like button. https://youtu.be/pkPRtQf6oQ8
By then I had already created the model (Post). Just when I added a new line (likes) in models.py and ran makemigrations, it migrated without any problem. But, when I ran migrate this error appeared.
Here is the models.py file
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')