Django如何使用现有模型迁移新模型

时间:2013-08-20 11:21:10

标签: django

是否有任何选项可以在django 1.4中使用现有模型更新新字段。我在models.py中有类名personaldetails,其中包含“name”,“dob”,“age”字段。现在我想在class.how中添加新字段“location”以在现有表中同步这个新字段。

2 个答案:

答案 0 :(得分:3)

您可以使用south之类的插件来实现此目标

答案 1 :(得分:1)

在没有南迁移的情况下,这是一种非常简单的方法。

first add the field name in your model and get under the shell type

$ python manage.py dbshell 

you will get directly within your database shell (mysql or psql) it up to what database
you are using.

mysql> | psql> ALTER TABLE <table_name> ADD column varchar(100);

and it will add the new column to your table, doesn't matter if the table it already
  populated or not.

$ python manage.py syncdb

就是这样,你很好