python-django-问题
django2.2版本
问题1:django.db.utils.OperationalError: (2006, 'MySQL server has gone away')
参考博文:https://www.cnblogs.com/ExMan/p/10171049.html
1 >>> from django.db import connection 2 >>> connection.close() 3 >>> import time 4 >>> time.sleep(10) 5 >>> User.objects.exists() 6 True 7 >>> User.objects.all()[:10] 8 <QuerySet [<User: weizitianming>, <User: weizitianming_0>, <User: weizitianming_1>, <User: weizitianming_2>, <User: weizitianming_3>, <User: weizitianming_4>, <User: weizitianming_5>, <User: weizitianming_6>, <User: weizitianmi 9 ng_7>, <User: weizitianming_8>]> 10 >>>
问题解决。
问题2,TypeError: __init__() missing 1 required positional argument: 'on_delete'
解决:添加 on_delete=models.CASCADE
参考链接:https://www.cnblogs.com/phyger/p/8035253.html
from django.db import models class Person(models.Model): name = models.CharField(max_length=50) class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField( Person, through='Membership', through_fields=('group', 'person'), ) class Membership(models.Model): group = models.ForeignKey(Group, on_delete=models.CASCADE) person = models.ForeignKey(Person, on_delete=models.CASCADE) inviter = models.ForeignKey( Person, on_delete=models.CASCADE, related_name="membership_invites", ) invite_reason = models.CharField(max_length=64)
问题3: mysqlclient 安装报错:OSError: mysql_config not found
#yum install mysql-devel gcc gcc-devel python-devel