What is the django command to delete all tables?

前端 未结 7 1965
清歌不尽
清歌不尽 2021-01-31 16:47

Are there django commands that

A. Delete all tables

B. delete all data in all tables

C. Create all tables as defined in the model?

7条回答
  •  醉梦人生
    2021-01-31 17:03

    A. Delete all tables

    manage.py sqlclear will print the sql statement to drop all tables

    B. delete all data in all tables

    manage.py flush returns the database to the state it was in immediately after syncdb was executed

    C. Create all tables as defined in the model?

    manage.py syncdb Creates the database tables for all apps in INSTALLED_APPS whose tables have not already been created.

    See this page for a reference of all commands: https://docs.djangoproject.com/en/dev/ref/django-admin/

    But you should definitely look into using south as someone already mentioned. It's the best way to manage your database.

    N.B: syncdb is deprecated in favour of migrate, since Django 1.7.

提交回复
热议问题