English 中文(简体)
在数据库中删除一个项目,而不是删除。
原标题:Disabling a item in the database instead of deleting it

是否有办法在数据库中删除该项目,而不是删除。

任何人都持有任何想法......

最佳回答

i 猜测,它取决于你通过拆解的含义。 您可添加一个<代码>Boolean Field,称为disabled,然后过滤你的询问(最好通过)。

Mymodel.objects.all()

do

Mymodel.objects.filter(disabled=False).all()
问题回答

Not in SQL. What you probably would be ending up doing to solve the problem is either

  • Moving the "disabled" values to another table, either by a trigger 或 st或ed procedure

  • Adding an active flag to the table with default value 1 and setting it to 0 instead of deleting. That would require an extra condition on every query (and active=1) that does not want to query disabled rec或ds.

You can set a field in the table which you set if the row is valid or unset if the row is deactivated.





相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签