django-orm 快速清理migrations缓存

Shell

#!/bin/bash

Project_dir=`pwd`
find $Project_dir -type d -a -name 'migrations' 
    -exec rm -rf {}/*_initial.py ;
echo "Done"

Python

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
for app in os.listdir(BASE_DIR):
    if os.path.isdir(app):
        migrations = os.path.join(BASE_DIR, app, 'migrations')
        if os.path.exists(migrations):
            for logfile in os.listdir(migrations):
                if not logfile.startswith('__'):
                    os.remove(os.path.join(migrations, logfile))
                    print('Del', os.path.join(migrations, logfile))
print('Done')
原文地址:https://www.cnblogs.com/meilong/p/djangoorm-kuai-su-qing-limigrations-huan-cun.html