/ 关系“main_post”处的 ProgrammingError 不存在
Posted
技术标签:
【中文标题】/ 关系“main_post”处的 ProgrammingError 不存在【英文标题】:ProgrammingError at / relation "main_post" does not exist 【发布时间】:2016-05-01 06:28:39 【问题描述】:您好,我正在使用 django 和 postgresql。我得到了上述错误。我有这样的数据库设置:
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.
【问题讨论】:
你能提供完整的堆栈错误吗?标题错误有点模棱两可。 @AaronLayfield opps 抱歉刚刚更新了 main_post 是否引用了您的 Django 应用程序中的任何内容?我看到您有一个名为main
的应用程序,并且发布的声音可能是该应用程序中的模型。 SQL 错误表明这是缺失的。尝试执行 python manage.py sqlflush
,然后执行 migrate
和 makemigrations
,以检查 Db 是否准确代表应用程序中的模型。
另外,请尝试syncdb
。
我尝试了所有这些但同样的错误,我不确定 main_post 来自哪里......我有一个名为 main 的应用程序和一个名为 Post 的模型。我看到它来自 post_list = Post.objects.all() post_list = sorted(post_list, key=lambda x: x.get_score(), reverse=True)
【参考方案1】:
用这种方法卸载 postgresql:How to thoroughly purge and reinstall postgresql on ubuntu? 然后在this youtube video 的帮助下重新安装解决了这个问题。
【讨论】:
以上是关于/ 关系“main_post”处的 ProgrammingError 不存在的主要内容,如果未能解决你的问题,请参考以下文章
Nest 无法解析 ItemsService (?) 的依赖关系。请确保索引 [0] 处的参数在 AppModule 上下文中可用
Nest 无法解析 JobsService (?) 的依赖关系。请确保索引 [0] 处的参数 JobModel 在 AppModule 上下文中可用
Coq无法使用Fix定义有根据的定义,但如果使用Program Fixpoint定义则可以
/sign-up/ 关系“auth_user”处的编程错误不存在第 1 行:从“auth_user”中选择(1)作为“a”在哪里“auth_user”。“userna [重复]