zoukankan      html  css  js  c++  java
  • 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的,但是没有设置为自增的!!或者数据定义的时候设置一个默认值就可以了。
  • 相关阅读:
    如何手动同步 Chrome 浏览器的数据
    如何释放 Windows 10 系统的 C 盘空间
    Foxmail
    常用 Git 命令
    常用的 .gitignore 模板
    MySQL InnoDB Engine--数据页存储和INSERT操作
    MySQL InnoDB Engine--数据页存储和ALTER TABLE操作
    MySQL InnoDB Engine--数据页存储
    MySQL Index--BAK和MRR演示
    MySQL Execute Plan--Index Merge特性
  • 原文地址:https://www.cnblogs.com/pyyu/p/9035599.html
Copyright © 2011-2022 走看看