python - 在 Django 模型中删除新列或删除现有表时如何保留以前的数据?
问题描述
我正在与开发人员组一起开发 ERP,我们需要在删除 Dajngo 模型和数据库的现有列或表时保留客户数据。
例如:
I added a column named columns1
and I gave the customer a release product of the System and then, but a week later I had to delete that new column
but the customer have data stores in the column1
column, here how can I preserve data or solve this situation.
Another Example:
I have a new column name column2
with unique
attr but here the customer have data, but I can not add new column with out allowed it to store the null data, but in this situation I do not want to allow the null data in column column2
and ether I can't put default
attr because it has unique
attr.
How to solve these things in Django
.
解决方案
我认为你需要在表字段名称中添加一个布尔字段删除如果你想删除列不要删除它把删除字段值设置为true。当您查询时添加条件删除 = false 的过滤器。我认为这适用于第一个条件
推荐阅读
- java - Firefox-Portable 的 Java Selenium 错误
- rest - Zalando 休息 API
- reactjs - 如何在使用 react-testing-library 和 jest 完成的单元测试中启用 react-i18n 翻译文件?
- java - VS-Code 中的 Java 项目,“vscode.java.validateLaunchConfig 没有 delegateCommandHandler”错误
- javascript - 访问按钮内的复选框值
- d3.js - D3js - 具有二进制值的折线图
- android - 如何在 Android 上的 Firebase 数据库中存储用户 Uid?
- angular - 如何将自定义配置传递给 ngx-imageviewer
- javascript - 在多个查询中使用 document.querySelectorALL 添加/删除类
- r - 如何编写一个 for 循环来解析 R 中的三个不同变量?