【问题标题】:South /Mezzanine/ Django - AttributeError: 'NoneType' object has no attribute 'lower'South /Mezzanine/ Django - AttributeError: 'NoneType' 对象没有属性 'lower'
【发布时间】:2012-08-09 07:44:49
【问题描述】:

这是 South & 尝试设置新环境的问题。在我的所有应用程序上运行迁移时,我收到以下错误:

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']"})
    },

我有点困惑,因为这个字段在迁移之间没有改变,而且夹层也没有改变。提前感谢您的想法。

【问题讨论】:

  • 您找到解决方案了吗?我正在努力解决同样的问题。

标签: django django-models django-south


【解决方案1】:

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

这似乎是一个如此明显的错误,很可能我的理解完全不正确,但据我所知,您应该能够手动编辑 South 生成的迁移脚本并删除对添加为新的通用关系字段的任何引用列。

【讨论】:

    猜你喜欢
    • 2020-12-08
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 2021-08-23
    • 2018-02-11
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多