码迷,mamicode.com
首页 > 其他好文 > 详细

Django2.2

时间:2020-05-07 15:39:24      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:models   red   required   details   sub   database   错误   data   foreign   

Django2.2

报错处理

  • 与mysql不兼容

    ImproperlyConfigured: mysqlclient 1.3.13 or newer is required
    
    1. 添加新版组件:

      pip install mysqlclient
      
    2. 移除旧版组件:

      pip uninstall pymysql
      
    3. 删除app目录下pymysql调用

      import pymysql
      
      pymysql.install_as_MySQLdb()
      
  • FoginKey报错:

    TypeError: CASCADE() missing 4 required positional arguments: ‘collector‘, ‘field‘, ‘sub_objs‘
    
    author_detail = models.OneToOneField("AuthorDetails", on_delete=models.CASCADE())
    

    models.CASCADE不能加()

    author_detail = models.OneToOneField("AuthorDetails", on_delete=models.CASCADE)
    
  • ORM报错:

    解决ORM错误:django.db.utils.IntegrityError: (1452, ‘Cannot add or update a child row: a foreign key constraint fails
    

    settings.py:取消外键检查

    # settings.py
    # 取消外键检查
    ‘OPTIONS‘:{
            "init_command":"SET foreign_key_checks = 0;",
    # 完整:
    DATABASES = {
        ‘default‘: {
            ‘ENGINE‘: ‘django.db.backends.mysql‘,
            ‘NAME‘: ‘test‘,
            ‘HOST‘:‘127.0.0.1‘,
            ‘PORT‘:3306,
            ‘USER‘:‘root‘,
            ‘PASSWORD‘:‘123‘,
            ‘OPTIONS‘: {
                "init_command": "SET foreign_key_checks = 0;",
            }
        }
    }
    

Django2.2

标签:models   red   required   details   sub   database   错误   data   foreign   

原文地址:https://www.cnblogs.com/relaxlee/p/12842917.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!