将字段添加到Django的现有数据库中(版本< 1.7) [英] Adding fields to an already existing database for Django (version < 1.7)

查看:82
本文介绍了将字段添加到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.

有没有办法


  1. 添加

  1. 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆