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

发布于 2024-10-07 18:46:20 字数 1715 浏览 9 评论 0原文

我创建了一个新模型:

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

$ python manage.py schemamigration forum --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'

I created a new model:

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

$ python manage.py schemamigration forum --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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷荒 2024-10-14 18:46:20

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

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

如果执行此操作,则必须将 Meta 添加到模型定义中:

class Meta:  
   app_label = 'APP_NAME'

如果不执行此操作,Django 将无法发现新模型。

My syntax was correct, the way I had created the model wasn't.

I had placed all my models into a directory /models

If you do this, you must add Meta to your model definition:

class Meta:  
   app_label = 'APP_NAME'

If you don't do this, Django can't discover the new models.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文