关于django:/ relation“main_post”中的ProgrammingError不存在

ProgrammingError at / relation “main_post” does not exist

您好我正在使用django和postgresql。 我收到了上述错误。 我有这样的数据库设置:

1
2
3
4
5
6
7
8
9
10
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'django_db',
        'USER': 'xxx',
        'PASSWORD':'xxxx',
        'HOST':'localhost',
        'PORT':'5432',
    }
}

对于像sqlite这样的问题,我只能删除db(mydatabase),但这次我看不到我的数据库在哪里。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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的输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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的输出:

1
2
3
4
5
6
7
8
9
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:如何在ubuntu上彻底清除并重新安装postgresql? 然后在这个youtube视频的帮助下重新安装修复了问题。