zoukankan      html  css  js  c++  java
  • python manage.py makemigrat Please select a fix: 1) Provide a one-off default now (will be set on all existing rows with a null value for this column) 2) Quit, and let me add a default in models.py

    更新models字段

    出现的问题:

    $ python manage.py makemigrations
    None
    You are trying to add a non-nullable field 'file_type' to filejinja without a default; we can't do that (the database needs something to populate existing rows).
    Please select a fix:
     1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
     2) Quit, and let me add a default in models.py
    Select an option:

    原因:

    之前数据表里面已经存在,如果添加,file_type需要默认值

    解决:

    方法1:

     在model字段后面添加,

     blank=True, null=True
        file_type = models.CharField(verbose_name="文件type", max_length=1, choices=(
            ('1', "配置文件"),
            ('2', "sls文件"),
        ), blank=True, null=True)

    再执行

    $ python manage.py makemigrations
    None
    Migrations for 'minions':
      appsminionsmigrations011_filejinja_file_type.py
        - Add field file_type to filejinja

     

    方法2:

    数据库中找到django_migrations,该表对应,每次makemigrations的每次记录

     删除,生成的migrations

    在删除你要更新的表。

    重新生成新的表

    $ python manage.py makemigrations
    None
    Migrations for 'minions':
      appsminionsmigrations010_filejinja.py
        - Create model FileJinja
    
    liangshuo@zt-2013326 MINGW64 /f/11_goms/goms (master)
    $ python manage.py migrate
    None
    Operations to perform:
      Apply all migrations: admin, auth, contenttypes, minions, salt, sessions
    Running migrations:
      Applying minions.0010_filejinja... OK

  • 相关阅读:
    python-web自动化-Js-滚动条操作
    python-web自动化-键盘操作
    python-web自动化:下拉列表操作
    python-web自动化-鼠标操作
    FastAPI 项目结构组织,工厂模式创建
    JavaScript fetch简单封装
    Python循环删除中遇到的小坑
    20200707 千锤百炼软工人第二天
    20200706 千锤百炼软工人第一天
    小谢第25问:iframe怎么向页面传值?
  • 原文地址:https://www.cnblogs.com/venicid/p/11993861.html
Copyright © 2011-2022 走看看