How to drop all tables from the database with manage.py CLI in Django?

前端 未结 18 1737
余生分开走
余生分开走 2020-11-29 16:54

How can I drop all tables from a database using manage.py and command line? Is there any way to do that executing manage.py with appropriate parameters so I can execute it f

18条回答
  •  误落风尘
    2020-11-29 17:49

    Using Python to make a flushproject command, you use :

    from django.db import connection
    cursor = connection.cursor()
    cursor.execute(“DROP DATABASE %s;”, [connection.settings_dict['NAME']])
    cursor.execute(“CREATE DATABASE %s;”, [connection.settings_dict['NAME']])
    

提交回复
热议问题