简体   繁体   English

将Django从1.8升级到1.9的问题

[英]Issue upgrading Django from 1.8 to 1.9

I am trying to upgrade Django from 1.8 to 1.9 but, when I run migrations it's throwing up error. 我正在尝试将Django从1.8升级到1.9,但是,当我运行迁移时,它会引发错误。 Below is the stack trace. 下面是堆栈跟踪。

Stack trace 堆栈跟踪

This is because of a new migration introduced in Django 1.9 which is to move auth username unicity logic from form to model [ref: ticket ]. 这是因为Django 1.9中引入了一个新迁移,该迁移将auth用户名唯一性逻辑从表单移动到模型[ref: ticket ]。 But, before upgrading we have implemented a little hack mentioned here to increase username character length from the default 30 character length to 75 characters. 但是,在升级之前,我们已经实施了此处提到的一点技巧 ,以将用户名字符长度从默认的30个字符长度增加到75个字符。 Now, when I run migrations it's considering only the first 30 characters of username and throwing up Integrity Error. 现在,当我运行迁移时,它只考虑用户名的前30个字符,并抛出Integrity Error。 Is there a way around this ? 有没有解决的办法 ? I don't want to go for a custom auth model as there are lot of complications involved. 我不想采用自定义身份验证模型,因为其中涉及许多复杂性。

First, migrate to migration 0006 if you haven't already. 首先,如果尚未迁移,则迁移到迁移0006。

./manage.py migrate auth 0006_require_contenttypes_0002

Then upgrade to Django 1.10 (or 1.11 LTS) once it's released, and fake migration 0007. 一旦发布,然后升级到Django 1.10(或1.11 LTS),并伪造迁移0007。

./manage.py migrate auth 0007_alter_validators_add_error_messages --fake

This migration is trying to reduce the column from 75 characters to 30 characters, so it must be faked. 此迁移尝试将列从75个字符减少到30个字符,因此必须将其伪造。

Then, you can run the rest of the migrations for auth : 然后,您可以运行auth的其余迁移:

./manage.py migrate auth

In particular, migration 0008 from Django 1.10 will increase the max length of the username to 150 characters. 特别是,从Django 1.10迁移0008会将用户名的最大长度增加到150个字符。 This means you can remove any hacks to alter the username max length that could cause problems. 这意味着您可以删除所有可能更改问题的用户名,以更改用户名的最大长度。

To be on the safe side, I wouldn't recommend faking 0007 and upgrading to Django 1.9. 为了安全起见,我不建议伪造0007并升级到Django 1.9。 I have no idea whether faking the migration and keeping your username length hack would work or cause problems I haven't thought of. 我不知道是假装迁移并保持用户名长度被破解还是会导致我没有想到的问题。

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

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