从Django 1.6(与南)升级到1.8不会在用户表上修改'last_login' [英] Upgrading from Django 1.6 (with south) to 1.8 doesn't modify 'last_login' on the user table

查看:337
本文介绍了从Django 1.6(与南)升级到1.8不会在用户表上修改'last_login'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从Django 1.6.5(南迁)升级到Django 1.8。我按照这里的说明:
https: //docs.djangoproject.com/en/1.8/topics/migrations/#upgrading-from-south



所以,我删除南,删除我以前的迁移并运行 python manage.py makemigrations ,这将创建一个新的迁移文件。然后我运行 python manage.py migrate --fake-initial 来伪造初始迁移。然后我运行 python manage.py migrate



这一切都运行良好,没有错误。



我有一个自定义用户模型继承 AbstractBaseUser 。在Django 1.8中,似乎有一个变化是 last_login 字段,它现在可以接受一个 null https:// docs .djangoproject.com / fr / 1.8 / ref / contrib / auth /#django.contrib.auth.models.User.last_login )。



问题我有,是迁移不会更改数据库表中的 last_login 字段来接受空值。结果,当我尝试保存时,我得到一个 IntegrityError (1048,列'last_login'不能为空)



如何解决这个问题?我需要手动更改数据库中的字段,还是有办法通过迁移进行修复?



修改
当我运行 python manage.py migrate --fake-initial 输出是这样的:
运行迁移:

 渲染模型状态... DONE 
应用contenttypes.0001_initial ... FAKED
应用contenttypes.0002_remove_content_type_name ... OK
应用验证。 0001_initial ... FAKED
应用auth.0002_alter_permission_name_max_length ... OK
应用auth.0003_alter_user_email_max_length ... OK
应用auth.0004_alter_user_username_opts ... OK
应用auth.0005_alter_user_last_login_null。 .. OK
应用auth.0006_require_contenttypes_0002 ... OK
应用core.0001_initial ... FAKED
应用admin.0001_initial ... FAKED
应用sessions.0001_initial ... FAKED

但是,当我查看数据库时,我仍然看到用户_last_login as not-null。

解决方案

1.8发行说明


如果您使用继承自 AbstractUser 的自定义用户模型,则需要运行 makemigrations 并为包含该模型的应用生成迁移。



I have upgraded from Django 1.6.5 (with south migrations) to Django 1.8. I have followed the instructions here: https://docs.djangoproject.com/en/1.8/topics/migrations/#upgrading-from-south

So, I remove South, delete my previous migrations and run python manage.py makemigrations which makes a new migration file. Then I run python manage.py migrate --fake-initial to fake the initial migration. Then I run python manage.py migrate.

It all runs fine with no errors.

I have a custom user model which inherits AbstractBaseUser. In Django 1.8 it seems there is a change to the last_login field where it is now able to accept a null value (https://docs.djangoproject.com/fr/1.8/ref/contrib/auth/#django.contrib.auth.models.User.last_login).

The problem I have, is that the migration does not change the last_login field in the database table to accept null values. As a result, when I try and save I get a IntegrityError saying (1048, "Column 'last_login' cannot be null").

How can I fix this? Do I need to manually change the field in the database, or is there a way to fix it with migrations?

Edit When I run python manage.py migrate --fake-initial the output is this: Running migrations:

  Rendering model states... DONE
  Applying contenttypes.0001_initial... FAKED
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... FAKED
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying core.0001_initial... FAKED
  Applying admin.0001_initial... FAKED
  Applying sessions.0001_initial... FAKED

However, when I look in the database I still see user_last_login as not-null.

解决方案

As noted in the 1.8 release notes:

If you are using a custom user model that inherits from AbstractUser, you’ll need to run makemigrations and generate a migration for your app that contains that model.

这篇关于从Django 1.6(与南)升级到1.8不会在用户表上修改'last_login'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆