【问题标题】:South Migration Issues南迁问题
【发布时间】:2014-09-17 08:58:42
【问题描述】:

我看过这些问题; http://south.readthedocs.org/en/latest/tutorial/part1.htmlSouth ignores change in field default value in Python / DjangoDjango-south not detecting DB changes 等等,但我似乎无法解决我的问题。

我有一个现有模型,其表中有数据,我正在通过外键向它添加另一个模型。我已经运行了模式迁移和迁移,但没有任何东西被证明是有效的。这是代码:

class UserNote(models.Model):
   user = models.ForeignKey(User)
   description = models.TextField(blank=True, null=True)

   created_at = models.DateTimeField(auto_now_add=True)
   updated_at = models.DateTimeField(auto_now=True)



class UserNoteType(models.Model):
    name = models.CharField(max_length=20)

我需要将 UserNoteType 作为外键添加到 UserNote,并且每次尝试添加该字段都会导致“未安装”、“未定义”。我已经为此奋斗了几个小时,任何帮助都会有很大帮助。

编辑: 当我尝试创建架构迁移时收到错误:

CommandError:一个或多个模型未验证: auth.usernote: 'note_type' 与 model 有关系,它要么没有安装,要么是抽象的。

【问题讨论】:

  • 你能发布完整的错误信息吗?它说的不仅仅是“未安装”或“未定义”吗?基本上,您正在运行的完整南命令是什么,以及错误的完整输出。
  • 它只是提到了模型。
  • CommandError: 一个或多个模型未验证:auth.usernote: 'note_type' 与模型 有关系,该模型要么未安装,要么是抽象的。
  • 这可能不是南方的错误,但一般来说你的模型。如果你只运行 python manage.py runserver 会发生什么,你也会得到同样的错误吗?首先要做的是确保您的模型得到验证。你能发布完整的模型文件吗?包括 UserNote 模型?
  • 我没有使用 .manage,我使用的是 django-admin.. 我的服务器运行完美。我只在这些迁移尝试中遇到了这个问题。

标签: python django postgresql database-migration django-south


【解决方案1】:

供您参考

如果你正在创建新项目,开始它自己需要设置south,试试下面:

python manage.py syncdb

python manage.py schemamigration --initial firstapp

python manage.py migrate forecasts --fake


python manage.py schemamigration --auto firstapp

python manage.py migrate google

你打算在开发端之后包含south,然后在下面尝试

./manage.py schemamigration --auto firstapp

./manage.py migrate firstapp

【讨论】:

【解决方案2】:

UserNote 模型已附加到 Django UserAuth 应用程序。这导致 South 每次都查找错误的应用程序。我通过创建自定义命令将新列 note_type 手动插入 UserNote 表来解决此问题。

非常感谢您的帮助。

【讨论】:

    【解决方案3】:

    您是否尝试使用以下命令将现有应用程序转换为 South?

    python manage.py convert_to_south my_app
    

    更多信息可以找到here

    【讨论】:

    • 感谢您的回复。当我尝试返回错误时,“没有启用的应用程序匹配'模型'”。即使按照建议运行 django-admin.py syncdb。
    • 如果您只迁移了一次模型,请删除应用程序中的“migrations”文件夹并执行“convert_to_south 命令”。否则,您能否以正确的顺序列出您运行的命令。这样,应该更容易理解你的错误。
    • 我删除了外键字段 > 在应用程序上运行 schemamigration --initial > 然后将外键添加到 UserNote 模型 > 运行另一个 schemamigration,这次使用了 --auto。而且我仍然收到错误消息,“note_type”与模型 有关系,该模型要么未安装,要么是抽象的。”
    猜你喜欢
    • 1970-01-01
    • 2013-04-08
    • 2014-08-06
    • 2011-11-25
    • 1970-01-01
    • 2011-04-03
    • 2013-01-02
    • 1970-01-01
    相关资源
    最近更新 更多