如何添加新模型并使用South 0.7.2生成迁移?

时间:2010-12-14 21:04:53

标签: django-models django-south

我创建了一个新模型:

class RssFeed(models.Model):  
  url = mdels.CharField(max_length=300)  

$ python manage.py schemamigration论坛--add-model RssFeed

  Traceback (most recent call last):
    File "manage.py", line 13, in <module>
      execute_manager(settings)
    File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/core/management/__init__.py", line 438, in execute_manager
      utility.execute()
    File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/core/management/__init__.py", line 379, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/core/management/base.py", line 191, in run_from_argv
      self.execute(*args, **options.__dict__)
    File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/core/management/base.py", line 220, in execute
      output = self.handle(*args, **options)
    File "/usr/local/lib/python2.7/site-packages/South-0.7.2-py2.7.egg/south/management/commands/schemamigration.py", line 134, in handle
      for action_name, params in change_source.get_changes():
    File "/usr/local/lib/python2.7/site-packages/South-0.7.2-py2.7.egg/south/creator/changes.py", line 397, in get_changes
      real_fields, meta, m2m_fields = self.split_model_def(model, model_defs[model_key(model)])
    File "/usr/local/lib/python2.7/site-packages/South-0.7.2-py2.7.egg/south/creator/freezer.py", line 58, in model_key
      return "%s.%s" % (model._meta.app_label, model._meta.object_name.lower())
  AttributeError: 'NoneType' object has no attribute '_meta'

1 个答案:

答案 0 :(得分:11)

我的语法是正确的,我创建模型的方式不是。

我已将所有模型放入目录/模型

如果这样做,则必须将Meta添加到模型定义中:

class Meta:  
   app_label = 'APP_NAME'

如果你不这样做,Django就无法发现新的模型。