Django 1.8运行特定的迁移

Django 1.8 Run a specific migration

在Django 1.8中,有没有一种方法可以运行特定的迁移,而该迁移仅限于此。

不是只针对一个应用程序,而是该应用程序迁移目录中的特定文件。

编辑为原始:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    Traceback (most recent call last):
  File"manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File"/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File"/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File"/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/core/management/base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File"/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File"/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 146, in handle
    plan = executor.migration_plan(targets)
  File"/home/vagrant/virtualenvs/aku/lib/python3.4/site-packages/django/db/migrations/executor.py", line 50, in migration_plan
    self.loader.graph.node_map[target].children
KeyError: ('wagtailcore', '0001_initial')

做了一点搜索,找到了这个https://code.djangoproject.com/ticket/24225 no1


您可以告诉Django移动到特定的迁移

1
./manage.py migrate myapp 0005_migration_to_run

但Django将运行每次迁移直到(或返回到)您选择的迁移。

你可以试着假装移民

1
2
./manage.py migrate --fake myapp 0004_previous_migration
./manage.py migrate myapp 0005_migration_to_run

然后,您可能想对您开始的迁移进行伪装。