将字段添加到Django的现有数据库中(版本< 1.7)

编程入门 行业动态 更新时间:2024-10-23 23:26:06
本文介绍了将字段添加到Django的现有数据库中(版本< 1.7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Django(< v1.7),并将SQLite3作为数据库引擎。

I'm using Django ( < v1.7), with SQLite3 as the database engine.

我正在尝试向现有的字段添加新字段模特的班级。此类已经有与之关联的数据。

I am trying to add a new field to an already existing model's class. This class already has data associated to it.

manage.py syncdb 不会在数据库中添加新字段。

manage.py syncdb is not adding the new fields to the db.

有没有办法

  • 添加

  • Add the new Field to the already existing class, and make sure a db entry is allocated to it?

    用一个空字符串为所有已经存在的新字段填充新字段,以确保已为该类分配一个db条目?

    Populate this new field with an empty string for all the already existing db entries?

    推荐答案

    在Django中向南安装即可轻松处理现有表格。检查此

    Install south in your django and you can easily handle the existing tables. check this

    如果真的想使用Django-South,将新字段添加到现有模型中后,将其安装在django上

    If you really want to use Django-South, install it on your django, after adding your new fields to your existing model run

    python manage.py schemamigration --initial

    python manage.py schemamigration --initial

    它将在您的项目应用程序中创建一个文件。然后,

    It will create a file in your project app. then,

    python manage.py migration

    python manage.py migrate

    就是这样,您的表格已更改。

    thats it your table is altered.

  • 更多推荐

    将字段添加到Django的现有数据库中(版本&lt; 1.7)

    本文发布于:2023-10-27 03:00:06,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1532111.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:字段   数据库中   版本   Django   amp

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!