简体   繁体   English

动态添加到Django模型

[英]Dynamically add to Django Model

I have need to dynamically (not manually edit models.py) alter/add/remove from a Django Model. 我需要从Django模型动态(而不是手动编辑models.py)更改/添加/删除。 Is this possible? 这可能吗? Once the model is altered, will it persist? 一旦更改了模型,它将继续存在吗? I then want to use South for running the database migration from the altered model. 然后,我想使用South从更改后的模型运行数据库迁移。

It sounds like you want your program to add and delete fields from the model? 听起来您想让程序从模型中添加和删除字段? That sounds like a bad idea. 听起来像个坏主意。 That would imply that your database schema will change dynamically under program control, which would be very unusual indeed. 这意味着您的数据库模式将在程序控制下动态更改,这确实是非常不寻常的。 Think harder about what data you need to represent, and come up with a database schema that works for all of your data. 仔细考虑一下您需要表示什么数据,并提出适用于所有数据的数据库架构。

Or, change to a non-SQL database, which means avoiding South altogether. 或者,更改为非SQL数据库,这意味着完全避免使用South。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM