【问题标题】:Your models have changes that are not yet reflected in a migration您的模型具有尚未反映在迁移中的更改
【发布时间】:2017-01-19 12:40:29
【问题描述】:

在django1.9中,表已经在数据库中,我创建了init迁移文件

    python manage.py makemigrations my_app

然后,我运行迁移:

    python manage.py migrate my_app

它显示:

    psycopg2.ProgrammingError: relation "p_record_segment" already exists

我想伪造它,首先,我清理 django_migrations,然后执行:

    python manage.py migrate my_app --fake 0001_initial

它显示:

    Running migrations:
        Rendering model states... DONE
        Applying my_app.0001_initial... FAKED

我认为这会很好,但是当我再次运行迁移时:

    Running migrations:
      No migrations to apply.
      Your models have changes that are not yet reflected in a migration, and so won't be applied.
      Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

我在 django_migrations 中看到了历史,实际上并没有改变,但是为什么 django 给我看这个。

【问题讨论】:

  • 该消息告诉您当前模型和迁移文件之间存在差异。这与数据库的当前状态无关。再次尝试运行manage.py makemigrations

标签: django


【解决方案1】:

尝试使用--fake-initial 而不仅仅是--fake

【讨论】:

    猜你喜欢
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    • 2015-12-12
    • 2016-10-28
    • 2016-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多