简体   繁体   English

makemigrations/migrate 错误 django.db.utils.OperationalError:没有这样的表

[英]makemigrations/migrate error django.db.utils.OperationalError: no such table

I have an application that I have made using PostgreSQL as a database management system, but due to a series of things that have happened, now I want to use SQLite, but when I run makemigrations or migrate, it throws me the error django.db.utils.OperationalError: no such table: blogapp_category.我有一个应用程序,我使用 PostgreSQL 作为数据库管理系统,但是由于发生了一系列事情,现在我想使用 SQLite,但是当我运行 makemigrations 或 migrate 时,它会抛出错误 Z2B9AFB89A6ACC10ADCAZB11。 .utils.OperationalError:没有这样的表:blogapp_category。 With PosgreSQL it works perfectly, but I can't get it to work with SQLite...使用 PosgreSQL 它可以完美运行,但我无法让它与 SQLite 一起使用...

(I have also tried to deploy the application with heroku and got the same error...) (我也尝试使用 heroku 部署应用程序并得到同样的错误......)

This is the traceback: Traceback这是回溯:回溯

These are my models:这些是我的模型:

blogapp\models.py blogapp\models.py

class Category(models.Model):
    name = models.CharField(max_length=255)

    class Meta:
    verbose_name_plural = 'Categories'

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('home')


class Post(models.Model):
    title = models.CharField(max_length=255)
    title_tag = models.CharField(max_length=255)
    author = models.ForeignKey(to=User, on_delete=models.CASCADE)
    # body = models.TextField()
    body = RichTextField(blank=True, null=True)
    post_date = models.DateField(auto_now_add=True)
    category = models.CharField(max_length=255, default='uncategorized')
    # category podría ser un ManyToManyField
    # https://stackoverflow.com/questions/2642613/what-is-related-name-used-for-in-django
    likes = models.ManyToManyField(
        to=User, related_name='blog_posts', blank=True)  # null has no effect on ManyToManyField
    snippet = models.CharField(max_length=255)
    header_image = models.ImageField(
        blank=True, null=True, upload_to='images/')

    def get_likes(self):
        return self.likes.count()

    def __str__(self):
        return '{} - {}'.format(self.title, self.author)

    def get_absolute_url(self):
        # https://docs.djangoproject.com/en/3.1/ref/urlresolvers/#reverse
        return reverse('article_detail', args=[str(self.id), ])
        # return reverse('home')

    class Meta:
        ordering = ['-post_date']


class Profile(models.Model):
    user = models.OneToOneField(to=User, null=True, on_delete=models.CASCADE)
    bio = models.TextField()
    profile_pic = models.ImageField(
        blank=True, null=True, upload_to='images/profile/')
    website_url = models.CharField(max_length=255, blank=True, null=True)
    fb_url = models.CharField(max_length=255, blank=True, null=True)
    twitter_url = models.CharField(max_length=255, blank=True, null=True)
    instagram_url = models.CharField(max_length=255, blank=True, null=True)
    pinterest_url = models.CharField(max_length=255, blank=True, null=True)
    # new
    followers = models.ManyToManyField(to=User, related_name='followers', blank=True)
    following = models.ManyToManyField(to=User, related_name='following', blank=True)
    default_home = models.BooleanField(default=True)
    # ---

   def __str__(self):
    return str(self.user)

    def get_absolute_url(self):
        return reverse('home')


class Comment(models.Model):
    post = models.ForeignKey(
        to=Post, related_name='comments', on_delete=models.CASCADE) # related_name es el nombre mediante el que vamos a poder acceder a los comentarios desde un post
    name = models.CharField(max_length=255)
    body = models.TextField()
    date_added = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return '{} - {}'.format(self.post.title, self.name)

membersapp\models.py membersapp\models.py

class DirectMessages(models.Model):
    sender = models.ForeignKey(to=User, on_delete=models.CASCADE, related_name="sender")
    reciever = models.ForeignKey(to=User, on_delete=models.CASCADE, related_name="recipent")
    text = models.TextField()
    timestamp = models.DateTimeField(auto_now_add=True)
    read = models.BooleanField(default=False)
    subject = models.TextField()

    class Meta:
        ordering = ['read', '-timestamp']

And this is the database configuration in settings.py:这是settings.py中的数据库配置:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': BASE_DIR / 'db.sqlite3',
    }
 }

I have an application that I have made using PostgreSQL as a database management system, but due to a series of things that have happened, now I want to use SQLite, but when I run makemigrations or migrate, it throws me the error django.db.utils.OperationalError: no such table: blogapp_category.我有一个应用程序,我使用 PostgreSQL 作为数据库管理系统,但是由于发生了一系列事情,现在我想使用 SQLite,但是当我运行 makemigrations 或 migrate 时,它会抛出错误 Z2B9AFB89A6ACC10ADCAZB11。 .utils.OperationalError:没有这样的表:blogapp_category。 With PosgreSQL it works perfectly, but I can't get it to work with SQLite...使用 PosgreSQL 它可以完美运行,但我无法让它与 SQLite 一起使用...

(I have also tried to deploy the application with heroku and got the same error...) (我也尝试使用 heroku 部署应用程序并得到同样的错误......)

This is the traceback: Traceback这是回溯:回溯

These are my models:这些是我的模型:

blogapp\models.py blogapp\models.py

class Category(models.Model):
    name = models.CharField(max_length=255)

    class Meta:
    verbose_name_plural = 'Categories'

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('home')


class Post(models.Model):
    title = models.CharField(max_length=255)
    title_tag = models.CharField(max_length=255)
    author = models.ForeignKey(to=User, on_delete=models.CASCADE)
    # body = models.TextField()
    body = RichTextField(blank=True, null=True)
    post_date = models.DateField(auto_now_add=True)
    category = models.CharField(max_length=255, default='uncategorized')
    # category podría ser un ManyToManyField
    # https://stackoverflow.com/questions/2642613/what-is-related-name-used-for-in-django
    likes = models.ManyToManyField(
        to=User, related_name='blog_posts', blank=True)  # null has no effect on ManyToManyField
    snippet = models.CharField(max_length=255)
    header_image = models.ImageField(
        blank=True, null=True, upload_to='images/')

    def get_likes(self):
        return self.likes.count()

    def __str__(self):
        return '{} - {}'.format(self.title, self.author)

    def get_absolute_url(self):
        # https://docs.djangoproject.com/en/3.1/ref/urlresolvers/#reverse
        return reverse('article_detail', args=[str(self.id), ])
        # return reverse('home')

    class Meta:
        ordering = ['-post_date']


class Profile(models.Model):
    user = models.OneToOneField(to=User, null=True, on_delete=models.CASCADE)
    bio = models.TextField()
    profile_pic = models.ImageField(
        blank=True, null=True, upload_to='images/profile/')
    website_url = models.CharField(max_length=255, blank=True, null=True)
    fb_url = models.CharField(max_length=255, blank=True, null=True)
    twitter_url = models.CharField(max_length=255, blank=True, null=True)
    instagram_url = models.CharField(max_length=255, blank=True, null=True)
    pinterest_url = models.CharField(max_length=255, blank=True, null=True)
    # new
    followers = models.ManyToManyField(to=User, related_name='followers', blank=True)
    following = models.ManyToManyField(to=User, related_name='following', blank=True)
    default_home = models.BooleanField(default=True)
    # ---

   def __str__(self):
    return str(self.user)

    def get_absolute_url(self):
        return reverse('home')


class Comment(models.Model):
    post = models.ForeignKey(
        to=Post, related_name='comments', on_delete=models.CASCADE) # related_name es el nombre mediante el que vamos a poder acceder a los comentarios desde un post
    name = models.CharField(max_length=255)
    body = models.TextField()
    date_added = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return '{} - {}'.format(self.post.title, self.name)

membersapp\models.py membersapp\models.py

class DirectMessages(models.Model):
    sender = models.ForeignKey(to=User, on_delete=models.CASCADE, related_name="sender")
    reciever = models.ForeignKey(to=User, on_delete=models.CASCADE, related_name="recipent")
    text = models.TextField()
    timestamp = models.DateTimeField(auto_now_add=True)
    read = models.BooleanField(default=False)
    subject = models.TextField()

    class Meta:
        ordering = ['read', '-timestamp']

And this is the database configuration in settings.py:这是settings.py中的数据库配置:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': BASE_DIR / 'db.sqlite3',
    }
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Makemigrations 错误:django.db.utils.OperationalError:没有这样的表 - Makemigrations error : django.db.utils.OperationalError: no such table Django迁移django.db.utils.OperationalError:没有这样的表: - Django migrate django.db.utils.OperationalError: no such table: 删除迁移和makemigrations之后django.db.utils.OperationalError - django.db.utils.OperationalError after removing migrations & makemigrations django.db.utils.OperationalError: 没有这样的表 Django 2 - django.db.utils.OperationalError: no such table Django 2 更改为PostgreSQL会引发django.db.utils.OperationalError:没有此类表错误 - Change to PostgreSQL raise django.db.utils.OperationalError: no such table Error django.db.utils.OperationalError: 没有这样的表 - django.db.utils.OperationalError: no such table PythonAnywhere:django.db.utils.OperationalError:没有这样的表: - PythonAnywhere: django.db.utils.OperationalError: no such table: 迁移错误(django.db.utils.OperationalError) - Migration error(django.db.utils.OperationalError) 尝试在Django 1.9中迁移 - 奇怪的SQL错误“django.db.utils.OperationalError:near”)“:语法错误” - Trying to migrate in Django 1.9 — strange SQL error “django.db.utils.OperationalError: near ”)“: syntax error” Django 2.2 - django.db.utils.OperationalError: 没有这样的表 - Django 2.2 - django.db.utils.OperationalError: no such table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM