zoukankan      html  css  js  c++  java
  • Django 2.1版本与Django 1.8.3的一些区别(转)

    Django 2.1版本与Django 1.8.3的一些区别

    我在刚开始学习的时候使用的Django版本是1.8.3的,后来在安装其它软件的时候,可能需要2.1的版本,自动帮我更新了Django2.1,然后重新运行之前的程序
    python manage.py runserver,就开始各种报错了。

    1、TypeError: _init_() missing 1 required positional argument: ‘on_delete’

    这是数据库设置外键的一个报错,在django2.0后,定义外键和一对一关系的时候需要加on_delete选项,此参数为了避免两个表里的数据不一致问题
    请参考:https://www.cnblogs.com/phyger/p/8035253.html

    第一个问题解决以后,接下来又出现另外一个问题。

    2、django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead.

    这是 urls的报错。
    在项目的主urls.py中设置
    这是原来的配置:
    原设置
    修改后的配置:
    这里写图片描述
    把第一组url的include()去掉。

    前面两个问题都解决之后,又出现第三个问题。

    3、django.db.utils.ProgrammingError: (1064, “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED’ at line 1”)

    这次是数据库的设置错误。
    在setting.py文件中找到DATABASES,然后添加一行代码
    ‘OPTIONS’: {‘isolation_level’: None}
    这里写图片描述
    保存!

    再运行python manage.py runserver,运行成功!但这里它会提示
    **You have 5 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth.
    Run ‘python manage.py migrate’ to apply them.**

    直接再运行python manage.py migrate把文件再迁移一下就可以了!

  • 相关阅读:
    Java3D实例应用载入VRML模型
    Tomcat数据库连接池的配置方法总结
    WebGL学习笔记使用3D引擎threeJS实现星空粒子移动
    mybatis应用实例学习
    springmvc 实例应用
    springmvc定制伪REST风格及JSR303Bean校验整合
    SpringMVC中应用Ajax异步通讯
    Java3D实例应用载入3ds 模型
    Device Mutipath参数设置
    Nginx+FastCGI+Python
  • 原文地址:https://www.cnblogs.com/it-tsz/p/10267966.html
Copyright © 2011-2022 走看看