3

当我尝试这个时,我收到了这个错误:

来源 ./env/bin/activate

sudo python manage.py syncdb

错误:没有名为 south 的模块

我在激活虚拟环境后安装了南,使用 pip install south(以及 django)。

在 settings.py 中安装的应用程序:

INSTALLED_APPS = (
    'south',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',

可能是什么问题呢?

更新:尝试在没有 sudo 的情况下同步时出现此错误。也许它与“南方”问题有关:

(env)andrius@ubuntu:~/djcode/myproject$ python manage.py syncdb

Syncing...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/home/andrius/env/local/lib/python2.7/site-packages/south/management/commands/syncdb.py", line 90, in handle_noargs
    syncdb.Command().execute(**options)
  File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "/home/andrius/env/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 306, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/home/andrius/env/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
    self.connection = Database.connect(**conn_params)
  File "/home/andrius/env/local/lib/python2.7/site-packages/psycopg2-2.4.6-py2.7-linux-x86_64.egg/psycopg2/__init__.py", line 178, in connect
    return _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATAL:  Peer authentication failed for user "django"

我使用这些命令为数据库创建了数据库和用户:

template1=# create database finance;
CREATE DATABASE
template1=# grant all privileges on database finance to django;
ERROR:  role "django" does not exist
template1=# create user django with password 'mydb123';
CREATE ROLE
template1=# grant all privileges on database finance to django;
GRANT
template1=# \q

我在 settings.py 中的数据库设置:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'finance',                      # Or path to database file if using sqlite3.
        'USER': 'django',                      # Not used with sqlite3.
        'PASSWORD': 'mydb123',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }

}

4

2 回答 2

8

安装南或运行同步数据库时不要成为 sudoer。做就是了

点安装南
python manage.py syncdb
于 2013-01-05T15:25:48.383 回答
0

只需从已安装的应用程序中删除南

Django 1.7 及更高版本不需要 South

要删除 south 使用 pip uninstall south 然后 y 完全删除它

于 2016-06-18T10:05:02.340 回答