Django4.0 遷移-撤銷遷移

2022-03-16 17:50 更新

可以通過 ?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

如果要撤消應(yīng)用于一個應(yīng)用的所有遷移,請使用名稱 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

如果遷移包含任何不可逆的操作,則該遷移是不可逆的。 試圖撤銷這種遷移將引發(fā) ?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 <RunSQL  sql='DROP TABLE demo_books'> in books.0003_auto is not reversible


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號