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

前端 未结 18 1693
余生分开走
余生分开走 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:39

    This answer is for postgresql DB:

    Run: echo 'drop owned by some_user' | ./manage.py dbshell

    NOTE: some_user is the name of the user you use to access the database, see settings.py file:

    default_database = {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'somedbname',
        'USER': 'some_user',
        'PASSWORD': 'somepass',
        'HOST': 'postgresql',
        'PORT': '',
    }
    

提交回复
热议问题