• Django开发问题及解决方法汇总


    1.

    manage.py@MxOnline > makemigrations users
    
    manage.py@MxOnline > migrate users

     2.

    操作django的admin,添加用户时报错:
    1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`))')

    解决方法:

    在settings.py中添加databases的参数

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': "mxonline",
            "USER": "root",
            "PASSWORD": "redhat",
            "HOST": "127.0.0.1",
            #解决admin的外键报错
            "OPTIONS": {
                "init_command": "SET foreign_key_checks=0;",
            }
        }
    }

     3.python3  xadmin在python3配置过程出现

    NameError: name 'reload' is not defined报错

    解决办法:

    不能pip install xadmin

    需要在https://github.com/sshwsfc/xadmin网址这里下载xadmin

     pip install git+git://github.com/sshwsfc/xadmin.git

    Field 'id' doesn't have a default value 原因

    Field 'id' doesn't have a default value昨晚做项目的时候遇到一个问题,在测试数据存储的时候老是报Field 'id' doesn't have a default value异常,从网上找了好久,根据各位大虾的说法也测试了好久好久,可就是没发现原因所在,鼓捣了两三个小时的时间,最后总算找到问题所在:原来是我的数据设计的时候,把主键的类型定义为int的,原本想是用自增的方式来的,可是由于自己的粗心,写sql语句的时候没有加上auto_increment,所以在数据存储的时候老是报Field 'id' doesn't have a default value,id根本就没有值啊!!
    加上自己从网上找的其他人说的他们遇到这种时候的原因,在这里总结一下:
    1、打开my.ini,查找
    sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    
    修改为
    sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    
    然后重启MYSQL
    
    2、MySQL 5 uses a strict mode which needs to be disabled.
    In Windows, Goto Start-->Programs-->MySQL->MySQL Instance Config Wizard. Follow through the Reconfigure Instance option-->Detailed Configuration-->Continue Next a few screens. At the bottom under Enable TCP/IP option there is 'Enable Strict Mode'. Deslect this option (no tick). Save changes and MySQL will restart.
    
    3、看看你的数据库定义的时候是不是把主键生成方式设置为int的,但是没有设置为自增的!!或者数据定义的时候设置一个默认值就可以了。
  • 相关阅读:
    Windows 7 x64 (英文操作系统)安装SQLServer 2005版本相关解决方法
    vs2008打开vs2010所做的项目的方法
    sqlserver2008 创建自动备份任务(图文教程)
    js返回上一页,自动刷新自身、父页面语句的实现
    有效的更改IE、Firefox、Chrome浏览器缓存位置的方法
    oo第二次总结
    OO第一次博客总结
    Ansible常用命令整理
    APM全链路监控日志收集篇
    TCP 和 UDP 的区别还有一个UTP一
  • 原文地址:https://www.cnblogs.com/pyyu/p/9035599.html
Copyright © 2020-2023  润新知