简体   繁体   English

Django 迁移没有迁移 authtoken 和会话

[英]Django migration didn't migrate authtoken and sessions

When running python manage.py migrate not all migrations were run, specifically django_celery_results , authtoken and sessions .运行python manage.py migrate并非所有迁移都运行,特别是django_celery_resultsauthtokensessions This resulted in the application related migrations erroring out.这导致与应用程序相关的迁移出错。

终端输出如下所示:

However, if I first manually migrate those three, and then specifically migrate auth (not sure why I'd need to migrate that again) and then do python manage.py migrate it'll work.但是,如果我首先手动迁移这三个,然后专门迁移auth (不知道为什么我需要再次迁移),然后执行python manage.py migrate它会起作用。

在此处输入图片说明

The installed apps on Django are like so: Django 上安装的应用程序是这样的:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'django_celery_results',
    'celery.contrib.testing.tasks',
    'api_app'
]

I'm wondering why that's happening, I thought migrate will run all the migrations listed in "operations to perform".我想知道为什么会这样,我认为migrate将运行“要执行的操作”中列出的所有迁移。

Your api_app.0002 migration creates a user without setting last_login .您的api_app.0002迁移会在不设置last_login情况下创建用户。 Therefore this migration must be run after the auth 0005 migration that allows nulls in this column.因此,此迁移必须在允许此列中存在空值的 auth 0005 迁移之后运行。

If you add a dependency to your migration, then Django will run them in the correct order.如果您向迁移添加依赖项,那么 Django 将按正确顺序运行它们。

class Migration(migrations.Migration):

    dependencies = [('auth', '0005_alter_user_last_login_null')]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM