Django2.2

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;",
            }
        }
    }
    
posted @ 2020-05-07 14:39  ManIThMrrr  阅读(121)  评论(0编辑  收藏  举报