django.db.utils.OperationalError:没有这样的表Django 2

问题描述 投票:0回答:1

我做了什么1.我删除了数据库2.删除pycache文件和迁移文件3. python manage.py makemigrations app_name和python manage.py migration app_name4.关闭服务器几次但这是我收到的错误enter image description here

settings.py

INSTALLED_APPS = [
    'blog',
    'users',
    'crispy_forms',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

]

users / models.py

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    image = models.ImageField(default='default.jpg', upload_to='profile_pics')

    def __str__(self):
        return f'{self.user.username} Profile'

    def save(self, *args, **kwargs):
        super().save()

        img = Image.open(self.image.path)

        if img.height > 300 or img.width > 300:
            output_size = (300, 300)
            img.thumbnail(output_size)
            img.save(self.image.path)

blog / models.py

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)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('post-detail', kwargs={'pk': self.pk})
python django django-models database-migration
1个回答
0
投票
我认为您没有正确迁移博客应用程序模型。您可以显示博客应用的迁移文件吗并且您应该在模型中的Meta类中定义db_name,否则您的模型将被绑定到您的应用程序,这将来可能会给您带来麻烦
© www.soinside.com 2019 - 2024. All rights reserved.