South / Mezzanine / Django - AttributeError:'NoneType'对象没有属性'lower'

时间:2012-08-13 04:27:56

标签: django django-models django-south

这是South& S的一个问题。试图建立一个新的环境。在我的所有应用程序上运行迁移时,出现以下错误:

Traceback (most recent call last):
  File "/Users/emilepetrone/Sites/tindie2/lib/python2.7/site-packages/south/migration/migrators.py", line 175, in _run_migration
    migration_function()
  File "/Users/emilepetrone/Sites/tindie2/lib/python2.7/site-packages/south/migration/migrators.py", line 57, in <lambda>
    return (lambda: direction(orm))
  File "/Users/emilepetrone/Sites/tindie2/tindie/tindie/apps/seller/migrations/0001_initial.py", line 26, in forwards
    ('comments', self.gf('mezzanine.generic.fields.CommentsField')(object_id_field='object_pk', to=orm['generic.ThreadedComment'])),
  File "/Users/emilepetrone/Sites/tindie2/lib/python2.7/site-packages/south/db/generic.py", line 44, in _cache_clear
    return func(self, table, *args, **opts)
  File "/Users/emilepetrone/Sites/tindie2/lib/python2.7/site-packages/south/db/generic.py", line 343, in create_table
    for field_name, field in fields
  File "/Users/emilepetrone/Sites/tindie2/lib/python2.7/site-packages/south/db/generic.py", line 643, in column_sql
    field = self._field_sanity(field)
  File "/Users/emilepetrone/Sites/tindie2/lib/python2.7/site-packages/south/db/mysql.py", line 263, in _field_sanity
    type = self._db_type_for_alter_column(field).lower()
AttributeError: 'NoneType' object has no attribute 'lower'

这似乎是我上一次模式移植的问题,或者是我的models.py中的问题。

在我的模型中,该字段看起来像(并且在迁移之间没有变化):

from mezzanine.generic.fields import CommentsField

class MyClass(models.Model):
    comments = CommentsField(verbose_name=_("Comments"))

来自迁移:

    'generic.threadedcomment': {
        'Meta': {'ordering': "('submit_date',)", 'object_name': 'ThreadedComment', '_ormbases': ['comments.Comment']},
        'by_author': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
        'comment_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['comments.Comment']", 'unique': 'True', 'primary_key': 'True'}),
        'replied_to': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'comments'", 'null': 'True', 'to': "orm['generic.ThreadedComment']"})
    },

我有点困惑,因为这个字段在迁移之间没有变化,&amp;夹层没变。提前感谢您的想法。

1 个答案:

答案 0 :(得分:0)

从我所看到的,问题是Mezzazine的CommentsField扩展GenericRelationGenericRelation.db_type()返回None,因为它是Django的语法糖并且字段没有模式中的列表示,但South仍在尝试生成ALTER TABLE SQL语句,并尝试通过有效调用None.lower()来设置列类型,这就是您获取异常的原因。

这似乎是一个明显的错误,很可能是我的理解完全没有,但从我看到你应该能够手动编辑South生成的迁移脚本并删除对作为新增加的通用关系字段的任何引用列。