Django Custom Management Script:在一个命令中删除所有迁移和数据库 [英] Django Custom Management Script: Deleting all migrations and database in one single command

查看:76
本文介绍了Django Custom Management Script:在一个命令中删除所有迁移和数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为django轮询应用程序编写管理脚本。
命令应删除所有迁移 pycache dbfile ,这样我以后就可以通过新的迁移重新开始...。

I am trying to write a management script for django polling app.. the command should delete all the migrations and pycache, and dbfile so that i can start out again later new with new migrations....

我的文件是 management / commands / removemigrations.py

from django.core.management.base import BaseCommand, CommandError
from polls.models import Question as Poll

class Command(BaseCommand):
    help = 'Delete migrations, pycache, dbfile, and all unwanted file'

    def add_arguments(self, parser):


    def handle(self, *args, **options):

我是django的新手,有人可以帮我制作这个脚本吗?我是新手。。谢谢

I am very new in django, can anyone help me to craft this script? I am very new.. Thanks

推荐答案

如果您使用的是基于Unix的系统,则可以使用bash命令:

If you're using unix based system, you could just use the bash commands:

find . -path "\*/migrations/\*.py" -not -name "\__init__.py" -delete    
find . -path "\*/migrations/\*.pyc"  -delete

您可以在以下位置了解更多信息:
https://simpleisbetterthancomplex.com/tutorial/2016/07/26/how-to-reset-migrations.html

you can read more about it at: https://simpleisbetterthancomplex.com/tutorial/2016/07/26/how-to-reset-migrations.html

这篇关于Django Custom Management Script:在一个命令中删除所有迁移和数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆