189 8069 5689

创新互联Django4.0教程:Django4.0迁移-撤销迁移

可以通过 ​migrate ​传递上一次迁移的编号来撤销迁移。例如,要撤销迁移 books.0003:

...\> py manage.py migrate books 0002
Operations to perform:
  Target specific migration: 0002_auto, from books
Running migrations:
  Rendering model states... DONE
  Unapplying books.0003_auto... OK

如果要撤消应用于一个应用的所有迁移,请使用名称 zero:

...\> py manage.py migrate books zero
Operations to perform:
  Unapply all migrations: books
Running migrations:
  Rendering model states... DONE
  Unapplying books.0002_auto... OK
  Unapplying books.0001_initial... OK

如果迁移包含任何不可逆的操作,则该迁移是不可逆的。 试图撤销这种迁移将引发 ​IrreversibleError​:

...\> py manage.py migrate books 0002
Operations to perform:
  Target specific migration: 0002_auto, from books
Running migrations:
  Rendering model states... DONE
  Unapplying books.0003_auto...Traceback (most recent call last):
django.db.migrations.exceptions.IrreversibleError: Operation  in books.0003_auto is not reversible

当前题目:创新互联Django4.0教程:Django4.0迁移-撤销迁移
文章链接:http://www.ptruijie.cn/article/dpjpgcp.html

其他资讯