python - Django/South 在 python manage.py schemamigration testapp --initial 上设置失败

标签 python django django-south

我第一次尝试在我的开发环境中设置 south。我之前已经设置了几个模型。 South 安装完成后,我按照 south 的文档转换我现有的应用程序。

但是,我得到了以下回溯。有什么想法吗?

谢谢。

./manage.py convert_to_south testapp
Creating __init__.py in '/home/testapp/../testapp/migrations'...
Traceback (most recent call last):
  File "./manage.py", line 14, in <module>
execute_manager(settings)
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.6/site-packages/South-0.7.6-py2.6.egg/south/management/commands/convert_to_south.py", line 70, in handle
management.call_command("schemamigration", app, initial=True, verbosity=verbosity)
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.6/site-packages/South-0.7.6-py2.6.egg/south/management/commands/schemamigration.py", line 140, in handle
    for action_name, params in change_source.get_changes():
  File "/usr/lib/python2.6/site-packages/South-0.7.6-py2.6.egg/south/creator/changes.py", line 444, in get_changes
    model_defs = freeze_apps([self.migrations.app_label()])
  File "/usr/lib/python2.6/site-packages/South-0.7.6-py2.6.egg/south/creator/freezer.py", line 35, in freeze_apps
    model_defs[model_key(model)] = prep_for_freeze(model)
  File "/usr/lib/python2.6/site-packages/South-0.7.6-py2.6.egg/south/creator/freezer.py", line 71, in prep_for_freeze
    fields = modelsinspector.get_model_fields(model, m2m=True)
  File "/usr/lib/python2.6/site-packages/South-0.7.6-py2.6.egg/south/modelsinspector.py", line 411, in get_model_fields
args, kwargs = introspector(field)
  File "/usr/lib/python2.6/site-packages/South-0.7.6-py2.6.egg/south/modelsinspector.py", line 371, in introspector
    kwargs[kwd] = get_value(field, defn)
  File "/usr/lib/python2.6/site-packages/South-0.7.6-py2.6.egg/south/modelsinspector.py", line 268, in get_value
    if "default" in options and value == options['default']:
  File "/usr/lib/python2.6/site-packages/django/db/models/fields/__init__.py", line 124, in __cmp__
    return cmp(self.creation_counter, other.creation_counter)
AttributeError: class NOT_PROVIDED has no attribute 'creation_counter'

这是我的模型代码。

我至少有 20 个表已经在使用 syncdb。我只是想转换到南方,因为删除表和​​重新创建是一件麻烦事。我已经删除了大部分模型代码以进行故障排除,这就是剩下的。即便如此,我也得到了完全相同的回溯。

import datetime
import urllib

from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.admin.util import quote
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode
from django.utils.safestring import mark_safe
from django.db import connection, transaction
"""
class BaseTable(models.Model):
    updated = models.DateTimeField(_('updated'), auto_now=True)
    created = models.DateTimeField(_('created'), auto_now_add=True)
    is_active = models.BooleanField(_('active'), default=True)   

    class Meta:
        abstract = True
"""

class UserProfile(models.Model):
    # This field is required.
    user = models.OneToOneField(User)
    # Other fields here
    accepted_eula = models.BooleanField()
    favorite_animal = models.CharField(max_length=20, default="Dragons")

最佳答案

为了让 South 使用开始跟踪预先存在的表,您必须在安装后立即运行 syncdb。换句话说,您应该遵循以下步骤:

$ pip install south
$ nano settings.py
Add south to installed apps & save
$ python manage.py syncdb
$ python manage.py convert_to_south <app>

关于python - Django/South 在 python manage.py schemamigration testapp --initial 上设置失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14721288/

相关文章:

mysql - South - 将 django 应用程序从 sqlite 迁移到 mysql

python - 为什么south要用迁移文件呢?

python - South 在尝试迁移时引发 ValueError

Python Tkinter 根标题不起作用

css - 无法在 Django 模板中加载字体

python - 如何在没有root权限的情况下部署nginx?

python - 带点的 Django URL

python - 字典中的 "TypeError: ' unicode ' object does not support item assignment"

python - Pandas rolling_sum 与中心和 min_periods

python - 使用 python 进行主成分回归