【问题标题】:Django how to migrate new models with existing modelDjango如何使用现有模型迁移新模型
【发布时间】:2013-08-20 11:21:10
【问题描述】:

是否有任何选项可以使用 django 1.4 中的现有模型更新新字段。我的类名个人详细信息在 models.py 中有字段“name”、“dob”、“age”。现在我想在类中添加新字段“位置”。如何在现有表中同步这个新字段。

【问题讨论】:

  • 您的问题找到解决方案了吗?
  • @abda2005 不,您建议 dbshel​​l 是手动过程。如果我对模型进行任何更改,每次我想更改表格。你还有什么想法

标签: django


【解决方案1】:

你可以使用像south这样的插件来实现这个

【讨论】:

  • 是的,它适用于 Django 1.4,请查看 link 以供参考
【解决方案2】:

一种非常简单的方法,无需向南迁移。

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

就是这样,你很好

【讨论】:

    猜你喜欢
    • 2015-08-01
    • 1970-01-01
    • 2012-12-26
    • 2022-06-17
    • 2017-03-20
    • 2021-08-25
    • 2015-09-12
    • 1970-01-01
    • 2021-10-26
    相关资源
    最近更新 更多