我正在使用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的现有数据库中(版本< 1.7)
发布评论