Flush just an app not the whole project

前端 未结 4 473
感动是毒
感动是毒 2021-02-04 01:08

python manage.py flush removes data from the entire project. I would like to be able to do python manage.py flush agivenapp How can I do this?

4条回答
  •  渐次进展
    2021-02-04 01:47

    I also needed something to empty only certain apps. I came up with this solution. This worked for mysql. It could be that the code needs to be changed for other databases.

    The main idea is not to do the whole 'flush'. Instead I get only what I want, with a grep from 'sqlflush'. You can also put everything in one line. For readability I split it up.

    BEGIN="BEGIN; SET FOREIGN_KEY_CHECKS = 0;"
    TRUNCATE=`./manage.py sqlflush |egrep " \\\`app1_| \\\`app2_"`
    END="SET FOREIGN_KEY_CHECKS = 1; COMMIT;"
    
    echo $BEGIN $TRUNCATE $END | ./manage.py dbshell
    

提交回复
热议问题