首页 > 解决方案 > 在进行迁移时,如何在没有 [Errno 13] Permission Denied 的情况下对 Django 提供的 User 模型进行猴子修补

问题描述

嘿伙计们,感谢您在以下方面的帮助:

我正在通过我创建的模型Contact(它包含关注者和我的关注者系统功能被关注的人)对用户模型进行猴子修补。

当我进行迁移时,我得到Permission Errno 13如下:

PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.4/dist-packages/django/contrib/auth/migrations/0010_user_following.py'

这是我的代码:

from django.db import models
from django.conf import settings
from django.contrib.auth.models import User


class Contact(models.Model):
    user_from = models.ForeignKey(User, related_name='rel_from_set', on_delete=models.CASCADE)
    user_to = models.ForeignKey(User, related_name='rel_to_set', on_delete=models.CASCADE)
    created = models.DateTimeField(auto_now_add=True, db_index=True)

    class Meta:
        ordering = ('-created',)

    def __str__(self):
        return '{} follows {}'.format(self.user_from, self.user_to)


User.add_to_class('following', models.ManyToManyField('self', through=Contact, related_name='followers', symmetrical=False))

标签: python-3.xdjango-modelsdjango-users

解决方案


推荐阅读