Django “关系”处的编程错误;“主邮政”;不存在
您好,我正在使用django和postgresql。我得到了上面的错误。我的数据库设置如下:Django “关系”处的编程错误;“主邮政”;不存在,django,postgresql,Django,Postgresql,您好,我正在使用django和postgresql。我得到了上面的错误。我的数据库设置如下: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'django_db', 'USER': 'xxx', 'PASSWORD':'xxxx', 'HOST':'localhost',
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_db',
'USER': 'xxx',
'PASSWORD':'xxxx',
'HOST':'localhost',
'PORT':'5432',
}
}
对于像sqlite这样的问题,我可以删除db(mydatabase),但这次我看不到我的db在哪里
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.8.4
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'tastypie')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/ebagu/main/views.py" in index
47. post_list = sorted(post_list, key=lambda x: x.get_score(), reverse=True)
File "/env/local/lib/python2.7/site-packages/django/db/models/query.py" in __iter__
162. self._fetch_all()
File "/env/local/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
965. self._result_cache = list(self.iterator())
File "/env/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator
238. results = compiler.execute_sql()
File "/env/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
840. cursor.execute(sql, params)
File "/env/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
79. return super(CursorDebugWrapper, self).execute(sql, params)
File "/env/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
64. .cursor.execute(sql, params)
File "/home/younggue/Desktop/ebagu1/env/local/lib/python2.7/site-packages/django/db/utils.py" in __exit__
97. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/env/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /
Exception Value: relation "main_post" does not exist
LINE 1: ...id", "main_post"."views", "main_post"."slug" FROM "main_post...
^
来自sqlflush
的输出:
BEGIN;
TRUNCATE "django_admin_log", "auth_permission", "auth_group", "auth_group_permissions", "django_session", "auth_user_groups", "auth_user_user_permissions", "main_category", "tastypie_apiaccess", "main_vote", "auth_user", "tastypie_apikey", "django_content_type";
SELECT setval(pg_get_serial_sequence('"django_admin_log"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"auth_permission"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"auth_group"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"auth_user"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"django_content_type"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"main_category"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"main_post"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"main_vote"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"tastypie_apiaccess"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"tastypie_apikey"','id'), 1, false);
COMMIT;
来自syncdb
/migrate
的输出:
Operations to perform:
Synchronize unmigrated apps: staticfiles, froala_editor, messages, crispy_forms
Apply all migrations: userena, sessions, admin, guardian, tastypie, auth, contenttypes, accounts, main, easy_thumbnails
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
No migrations to apply.
使用此方法卸载postgresql:然后在来自的帮助下重新安装,修复了此问题。能否提供完整的堆栈错误?标题错误有点含糊不清。@AaronLayfield opps抱歉,刚刚更新了Django应用程序中的任何内容的主要发布引用?我看到你有一个名为
main
的应用程序,post听起来像是这个应用程序中的一个模型。SQL错误表明缺少此项。尝试执行python manage.py sqlflush
,然后执行migrate
和makemigrations
以检查数据库是否准确表示应用程序中的模型。此外,请尝试syncdb
。我尝试了所有这些,但都出现了相同的错误,我不确定main_post来自哪里……我有一个名为main的应用程序和一个名为post的模型。我看到它来自post\u list=post.objects.all()post\u list=sorted(post\u list,key=lambda x:x.get\u score(),reverse=True)