python-3.x - 在进行迁移时,如何在没有 [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))
解决方案
推荐阅读
- ios - 我可以使用单个 Cocoapod 定位多个 Xcode/Swift 版本吗?
- c++ - 从类指针到 int 的无效转换
- mongodb - 在 spark + hdfs + mongo 环境中实现单元测试
- fpm - PHP-FPM 无法关闭
- log4j2 - How to set log4j2.json configuration.properties.property default value
- c++ - 如何读取 google::protobuf::io::CodedOutputStream::WriteVarint32ToArray 写入的数据
- scala - 如何从列表中创建火花数据框
- json - Clover ETL中提取json数据
- c# - 如何序列化已使用 XmlTextReader { Namespaces = false } 读取的 XML?
- java - 键盘隐藏 BottomSheetDialog