简体   繁体   中英

Change to PostgreSQL raise django.db.utils.OperationalError: no such table Error

I was developing with default DB SQLite for a Django project but now I need to deploy to Heroku so I switched to PostgreSQL. However, during the deployment, I kept getting django.db.utils.OperationalError: no such table: error:

full error in heroku logs --tail :

2019-02-08T13:56:10.598144+00:00 app[web.1]: Internal Server Error: /catelogue/floor
2019-02-08T13:56:10.598152+00:00 app[web.1]: Traceback (most recent call last):
2019-02-08T13:56:10.598154+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
2019-02-08T13:56:10.598156+00:00 app[web.1]: return self.cursor.execute(sql, params)
2019-02-08T13:56:10.598158+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 296, in execute
2019-02-08T13:56:10.598160+00:00 app[web.1]: return Database.Cursor.execute(self, query, params)
2019-02-08T13:56:10.598162+00:00 app[web.1]: sqlite3.OperationalError: no such table: product_floor

As you can see, there should be a table called product_floor in SQLite.

But the problem is, I have already updated my db configuration to PostgreSQL and deleted SQLite3 file in my project folder. I also deleted all migration files and cached files and ran python manage.py makemigrations and python manage.py migrate again.

When I turned DEBUG to true and access pages in the local browser, there's no problem. But when I access certain pages served in URL *.herokuapp.com/product/* (pages that use data from database), I got Server Error 500 .

My models.py

from django.db import models
from django.conf import settings
from django.utils import timezone

class Floor(models.Model):
    name = models.CharField(max_length=20, verbose_name='floor name')
    image = models.ImageField(
        upload_to='floor',
        blank=True,
        editable=True,
        verbose_name='floor image'
    )
    image_height = models.PositiveIntegerField(null=True, blank=True, editable=False, default="340")
    image_width = models.PositiveIntegerField(null=True, blank=True, editable=False, default="340")
    desc = models.CharField(max_length=256, verbose_name='floor description')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='floor price')

    class Meta:
        app_label = 'product'

    def __str__(self):
        return self.name
### Add some classes with almost same fields

My settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': '[DB NAME]',
        'USER': '[DB USER]',
        'PASSWORD': '[***]',
        'HOST': 'localhost',
        'PORT': '',
    }

Can anyone help me with this? Thanks a lot!

I finally got the answer. It seemed that I made a minor change to the db model, so after both migrate / makemigrations locally, it's suggested to run migrate again after deployment. Thank you all for the suggestions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM