Django


1342 浏览 6 years, 2 months

4.1 migrations

版权声明: 转载请注明出处 http://www.codingsoho.com/

Issue

No migrations to apply

Django keeps track of all the applied migrations in django_migrations table. So just delete all the rows in the django_migrations table that are related to you app like:

python manage.py makemigrations
python manage.py migrate

Django. No changes detected when "makemigrations"

在修改了models.py后,有些用户会喜欢用python manage.py makemigrations生成对应的py代码。

但有时执行python manage.py makemigrations命令,会提示"No changes detected." 可能有用的解决方式如下:

  1. 直接使用python manage.py migrate.
    可能会先生成对应数据库的py代码,再自动执行这段代码,创建数据库表格 (我没有仔细去读文档 不清楚这条命令的逻辑)

  2. 来自:https://docs.djangoproject.com/en/1.8/topics/migrations/
    python manage.py makemigrations --empty yourappname 生成一个空的initial.py
    python manage.py makemigrations 生成原先的model对应的migration file