Django关系“myapp_mymodel”不存在错误

时间:2018-02-15 15:44:57

标签: python django postgresql django-models

我最初尝试将CharField“NewsItem.markdown”的名称更改为“NewsItem.name”并更改其最大长度。 我按照惯例进行迁移和迁移,但是这导致了一个错误,告诉我“main_NewsItem.markdown”不存在。

在努力解决这个问题后(刷新数据库,删除数据库并重新创建数据库等而不改变错误消息)我决定一起删除该模型并创建一个名为“News_item”的新模型。我再次按照惯例进行迁移和迁移。

这导致以下错误:

Environment:


Request Method: GET
Request URL: http://46.101.55.192/admin/main/newsitem/

Django Version: 2.0.2
Python Version: 3.5.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'main']

Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

The above exception (relation "main_newsitem" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "main_newsitem"
                                      ^
) was the direct cause of the following exception:

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/core/handlers/base.py" in _get_response
  128.                 response = 
self.process_exception_by_middleware(e, request)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, 
 *callback_args, **callback_kwargs)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/contrib/admin/options.py" in wrapper
  574.                 return self.admin_site.admin_view(view)(*args, 
**kwargs)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, 
**kwargs)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/utils/decorators.py" in _wrapper
  62.             return bound_func(*args, **kwargs)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, 
**kwargs)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/utils/decorators.py" in bound_func
  58.                 return func.__get__(self, type(self))(*args2, 
**kwargs2)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/contrib/admin/options.py" in changelist_view
  1570.             cl = self.get_changelist_instance(request)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/contrib/admin/options.py" in get_changelist_instance
  705.             self,

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/contrib/admin/views/main.py" in __init__
  77.         self.get_results(request)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/contrib/admin/views/main.py" in get_results
  175.         result_count = paginator.count

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/utils/functional.py" in __get__
  36.         res = instance.__dict__[self.name] = self.func(instance)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/core/paginator.py" in count
  85.             return self.object_list.count()

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/db/models/query.py" in count
  387.         return self.query.get_count(using=self.db)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/db/models/sql/query.py" in get_count
  491.         number = obj.get_aggregation(using, ['__count'])
['__count']

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/db/models/sql/query.py" in get_aggregation
  476.         result = compiler.execute_sql(SINGLE)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/db/models/sql/compiler.py" in execute_sql
  1064.             cursor.execute(sql, params)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/db/backends/utils.py" in execute
  100.             return super().execute(sql, params)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/db/backends/utils.py" in execute
  68.         return self._execute_with_wrappers(sql, params, 
many=False, executor=self._execute)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/db/backends/utils.py" in _execute_with_wrappers
  77.         return executor(sql, params, many, context)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/db/utils.py" in __exit__
  89.                 raise dj_exc_value.with_traceback(traceback) 
from exc_value

File "/home/koan/koansite/koansiteenv/lib/python3.5/site-
packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /admin/main/newsitem/
Exception Value: relation "main_newsitem" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "main_newsitem"
                                      ^

这是main / models.py文件     来自django.db导入模型

class Image(models.Model):
    name = models.CharField(max_length=30)
    caption = models.CharField(max_length=1000)

    def __unicode__(self):
        return self.name

class Carousel(models.Model):
    name = models.CharField(max_length=50, default='ineedaname')
    images = models.ManyToManyField(Image)

    def __unicode__(self):
        return self.name

class News_item(models.Model):
    name = models.CharField(max_length=50, default='ineedaname')
    published_at = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return self.name + self.published_at

class Artist(models.Model):
    name = models.CharField(max_length=100)
    description = models.CharField(max_length=50000)
    releases = models.ManyToManyField('Release', blank=True)
    spotifylink = models.CharField(max_length=1000)
    soundcloudlink = models.CharField(max_length=1000)
    bandcamplink = models.CharField(max_length=1000)
    applemusiclink = models.CharField(max_length=1000)

    def __unicode__(self):
        return self.name

class Release(models.Model):
    title = models.CharField(max_length=200)
    typevideotrack = models.CharField(max_length=50)
    artists = models.ManyToManyField(Artist)
    releasedate = models.DateField()
    link = models.CharField(max_length=1000)

    def __unicode__(self):
        return self.title

我正在使用一个postgres数据库,我检查过的表格似乎都是正确的。

任何有关修复此问题的帮助都将受到赞赏。

由于

0 个答案:

没有答案