向现有数据库添加字段 [英] Adding fields to an already existing database

查看:248
本文介绍了向现有数据库添加字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Django,使用SQLite3作为数据库引擎。

I'm using Django, 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 没有将新字段添加到db

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

是否有办法:


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

使用空字符串填充所有已经存在的类的新字段db entries?

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


推荐答案

在你的django中安装south,现有表。请检查

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 migrate

python manage.py migrate

这是你的表被改变。

这篇关于向现有数据库添加字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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