关系" comparison_bundle"不存在LINE 1:SELECT COUNT(*)FROM" comparison_bundle"

时间:2014-12-01 11:57:17

标签: django postgresql django-models

这是我刚用Postgresql创建的一个新数据库。

当我进入管理页面时,除非我尝试使用“Bundle”模型,否则Everythin工作正常。

以下是模型:

class Company(models.Model):
    name = models.CharField(max_length=50)
    info = models.TextField()

def __str__(self):
    return self.name

class Bundle(models.Model):
    company = models.ForeignKey(Company, null=True)
    title = models.CharField(max_length=150)
    info = models.TextField(blank=True)
    price = models.credit = models.DecimalField(max_digits=15, decimal_places=4, null=True)

    def __str__(self):
        return self.title

Admin.py:

from django.contrib import admin
from models import Company, Bundle

class BundleAdmin(admin.ModelAdmin):
    fieldsets= [
        ('Bundles info', {'fields':['title', 'packet', 'info', 'price']}),
    ]

这就是我得到的:

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in wrapper
  584.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  105.                     response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
  204.             return view(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapper
  29.             return bound_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  105.                     response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in bound_func
  25.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in changelist_view
  1486.                 self.list_max_show_all, self.list_editable, self)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/views/main.py" in __init__
  110.         self.get_results(request)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/views/main.py" in get_results
  219.         result_count = paginator.count
File "/usr/local/lib/python2.7/dist-packages/django/core/paginator.py" in _get_count
  72.                 self._count = self.object_list.count()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in count
  338.         return self.query.get_count(using=self.db)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in get_count
  424.         number = obj.get_aggregation(using=using)[None]
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in get_aggregation
  390.         result = query.get_compiler(using).execute_sql(SINGLE)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in execute_sql
  786.             cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py" in execute
  81.             return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py" in execute
  65.                 return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py" in __exit__
  94.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py" in execute
  65.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /admin/comparison/bundle/
Exception Value: relation "comparison_bundle" does not exist
LINE 1: SELECT COUNT(*) FROM "comparison_bundle"

在终端中我收到此错误:

[01/Dec/2014 13:45:43] "GET /admin/comparison/bundle/ HTTP/1.1" 500 211501

这可能是因为我创建了一个新数据库并替换了settings.py中的旧数据库名称吗? 或者是因为我删除了迁移文件? 我不知道为什么会出现这个错误

1 个答案:

答案 0 :(得分:1)

首先,实际上,您可能只是忘记同步数据库。如果是这样,那就去做吧!:

python manage.py syncdb

如果没有,也许你需要完全删除数据库(如果你有数据)并重新开始。