【问题标题】:Django 1.6 editing userprofile model with existing usersDjango 1.6 使用现有用户编辑用户配置文件模型
【发布时间】:2014-06-17 21:43:59
【问题描述】:

我有一个 django 数据库,其中包含用于用户模型的自定义用户配置文件。 问题是,当我想向我的 userprofile 类添加新字段时,在尝试访问 users 表时,我收到关于新字段的错误 no such column

有什么方法可以更新用户配置文件模型而无需重建数据库?

谢谢。

【问题讨论】:

    标签: python django


    【解决方案1】:

    这里是如何做到这一点..

    先安装south

    pip install south
    

    然后将INSTALLED_APP列表添加到您的设置中-

       ...,
       'south',
       ...
    

    什么是南?.. 南是一个 django 应用程序,可帮助您更新数据库而无需重建它。现在初始化你的模型-

    python manage.py syncdb // this will create the south tables for migrations
    python manage.py schemamigration <appname> --initial //  (once per app) this will create the initial model files in a migrations package
    python manage.py migrate
    

    然后每次更新模型时只需执行更新 -

    python manage.py schemamigration <appname> --auto
    python manage.py migrate <appname>
    

    您可以在此处找到完整的文档 - http://south.readthedocs.org/en/latest/tutorial/

    【讨论】:

    • 感谢您的回答 Mahmud,我之前已经尝试过,但即使这样做我仍然会收到 no such column 错误,并且即使我重做数据库,我也会遇到同样的错误。我想我在那里遗漏了一些东西:(
    • 你能显示导致错误的代码或模型吗?
    • 好的,找到问题了。看来我不能用现有的字段来做到这一点。首先,我必须删除它们(或修改它们,以便南将删除并添加新的),然后使用新字段运行迁移。使用旧字段迁移不起作用:)
    • 是的,没错。它计算与x_initial.py 文件的差异。因此,如果它有列,则不会创建新列。
    猜你喜欢
    • 1970-01-01
    • 2020-07-03
    • 2014-04-29
    • 2018-10-05
    • 2016-05-19
    • 2014-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多