Python 3.3 + Django 1.6 + 连接器/Python Django 后端 + South

Posted

技术标签:

【中文标题】Python 3.3 + Django 1.6 + 连接器/Python Django 后端 + South【英文标题】:Python 3.3 + Django 1.6 + Connector/Python Django Backend + South 【发布时间】:2014-04-27 07:18:41 【问题描述】:

我想用这套:Ubuntu 12.04 + Python 3.3 + Django 1.6 + mysql 5.5;

为了支持 MySQL,我使用了“连接器/Python Django 后端”(link)。

我的设置:

DATABASES = 
    'default': 
        'NAME': 'test',
        'ENGINE': 'mysql.connector.django',
        'USER': 'root',
        'PASSWORD': '****',
        'OPTIONS': 
          'autocommit': True,
        ,
    

这是工作。

但我想使用“South”。我成功安装了“South”。

pip install south==0.8.4

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

这就是发生的事情

python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/mikhail/virtualenv/python3.3/lib/python3.3/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/home/mikhail/virtualenv/python3.3/lib/python3.3/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/mikhail/virtualenv/python3.3/lib/python3.3/site-packages/django/core/management/__init__.py", line 272, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/mikhail/virtualenv/python3.3/lib/python3.3/site-packages/django/core/management/__init__.py", line 75, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/home/mikhail/virtualenv/python3.3/lib/python3.3/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1512, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1022, in load_module
  File "<frozen importlib._bootstrap>", line 1003, in load_module
  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 868, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "/home/mikhail/virtualenv/python3.3/lib/python3.3/site-packages/south/management/commands/__init__.py", line 13, in <module>
    from south.management.commands.syncdb import Command as SyncCommand
  File "/home/mikhail/virtualenv/python3.3/lib/python3.3/site-packages/south/management/commands/syncdb.py", line 19, in <module>
    from south.db import dbs
  File "/home/mikhail/virtualenv/python3.3/lib/python3.3/site-packages/south/db/__init__.py", line 83, in <module>
    db = dbs[DEFAULT_DB_ALIAS]
KeyError: 'default'

怎么办?

【问题讨论】:

你能用django mysql引擎试试吗? django.db.backends.mysql "在撰写本文时,最新版本的 MySQLdb (1.2.4) 不支持 Python 3。为了在 Python 3 下使用 MySQL,您必须安装非官方的 fork ,例如 MySQL-for-Python-3。”。这是 Django 1.6 的官方手册。我还没试过用Mysql后端。 【参考方案1】:

要支持 MySQL 需要使用 MySQL-for-Python-3 (link)

安装:

$ tar xfz MySQL-python-1.2.1.tar.gz
$ cd MySQL-python-1.2.1
$ python setup.py build
$ sudo python setup.py install

Django 官方手册的下一步。

【讨论】:

以上是关于Python 3.3 + Django 1.6 + 连接器/Python Django 后端 + South的主要内容,如果未能解决你的问题,请参考以下文章

用于学习 Django 的 Python 2.7 或 3.3

python 从ramusus分发:https://gist.github.com/ramusus/4343464并更改为在Django 1.6中工作,仅针对OneToOne关系进行了更改测试(o

Django 1.6:如何访问视图中的静态文件

django 安装

PHP5.3.3升级PHP7.1.6

Nginx+uwsgi+virtualenv+Django+Mysql架构