在 Django 中更新模型的正确方法
我不断修改 Django 中的模型。但是,完成此操作后,我必须进入数据库,手动删除表,然后 manage.pysyncdb
。我尝试 manage.py reset <
但它没有下降,然后使用新字段重新安装模型。执行此操作的正确方法是什么,或者进入数据库、删除然后同步数据库的最佳方法是什么?
I keep modifying my model in Django. However after I do it I have to go into the database, delete the table manually and then manage.py syncdb
. I tried manage.py reset <<app_name>>
but it doesn't drop then reinstall the model with the new fields. What is the proper way to do this or is the best way to go into the database, delete, then syncdb?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档中明确提到了您描述的行为:
您需要的是一个数据库迁移工具,是一个大问题大部分已解决;-)
所以,是的,正如 Marcin 所说,您正在寻找南。
或者,您可以尝试Nashvegas,甚至进行一些小的更改
sql_diff
是django-extensions
是一个可行的选择。The behaviour you describe is explicitly mentioned in the docs:
What you are after is a tool for database migrations and that is a large problem mostly solved ;-)
So yes, as Marcin said, your are looking for South.
Alternatively you could try Nashvegas and for small changes even
sql_diff
which is part ofdjango-extensions
is a viable option.