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把文件再迁移一下就可以了!

  • 相关阅读:
    JAVA 字符处理
    android:visibility 隐藏 可见 不可见
    Android中 int 和 String 互相转换的多种方法
    日期月和日补零
    【程序】程序报错 error:-1610149839 等大负数
    【IE】将IE11改为64位
    【linux】CentOS网络配置
    【linux】CentOS虚拟机eth0 提示Device does not seem to be present
    【SUSE】关闭防火墙
    【走马观花】十月八日通州雾
  • 原文地址:https://www.cnblogs.com/it-tsz/p/10267966.html
Copyright © 2011-2022 走看看