django.db.migrations.exceptions.InconsistentMigrationHistory在新数据库上

时间:2019-06-11 21:01:10

标签: python django python-3.x django-models django-migrations

文件夹结构:

-project/
  -project/
    -manage.py
    -settings.py
    -urls.py
    -wsgi.py
  -apps/
    -user/
      -migrations/
        -migration files here
      -models.py

用户模型:

from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone


class User(AbstractUser):
    timestamp = models.DateTimeField(default=timezone.now, db_index=True)

    class Meta:
        swappable = 'AUTH_USER_MODEL'

settings.py:

INSTALLED_APPS = [
    # user
    'apps.user.apps.UserConfig',

    # built-in
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    # third party
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth',
    'allauth',
    'allauth.account',
    'rest_auth.registration',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
]

AUTH_USER_MODEL = 'user.User'

我尝试过的方法(每个新代码块都在新的数据库上运行,而应用程序用户没有任何迁移文件):

python manage.py makemigrations user
python manage.py migrate

python manage.py makemigrations user
python manage.py migrate user

python manage.py migrate
python manage.py makemigrations user
python manage.py migrate user

所有这些都导致以下异常:

django.db.migrations.exceptions.InconsistentMigrationHistory: Migration authtoken.0001_initial is applied before its dependency user.0001_initial on da

tabase“默认”。

0 个答案:

没有答案