更新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:
) Provide a one-off default now (will be set on all existing rows with a null value for this column)
) 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=, choices=(
('', "配置文件"),
('', "sls文件"),
), blank=True, null=True)

再执行

$ python manage.py makemigrations
None
Migrations for 'minions':
apps\minions\migrations\0011_filejinja_file_type.py
- Add field file_type to filejinja

方法2:

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

删除,生成的migrations

在删除你要更新的表。

重新生成新的表

$ python manage.py makemigrations
None
Migrations for 'minions':
apps\minions\migrations\0010_filejinja.py
- Create model FileJinja liangshuo@zt- 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 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的更多相关文章

  1. $ python manage.py makemigrations You are trying to add a non-nullable field 'name' to course without a default; we can't do that (the database needs something to populate existing rows). Please selec

    问题: $ python manage.py makemigrationsYou are trying to add a non-nullable field 'name' to course wit ...

  2. 【解决方案】django初始化执行python manage.py migrate命令后,除default数据库之外的其他数据库中的表没有创建出来

    [问题原因]:django工程中存在多个应用,每个应用都指定了对应的数据库.执行python manage.py migrate命令时没有指定数据库,将只初始化默认的default数据库. [解决方案 ...

  3. python manage.py shell之后的一些错误:

    1. 在执行python manage.py shell之后的一些错误: wyl@wyl:~/myobject$ python manage.py shell /usr/lib/python2.7/d ...

  4. Python Django CMDB项目实战之-2创建APP、建模(models.py)、数据库同步、高级URL、前端页面展示数据库中数据

    基于之前的项目代码来编写 Python Django CMDB项目实战之-1如何开启一个Django-并设置base页index页文章页面 现在我们修改一个文章列表是从数据库中获取数据, 下面我们就需 ...

  5. django源码分析 python manage.py runserver

    django是一个快速开发web应用的框架, 笔者也在django框架上开发不少web应用,闲来无事,就想探究一下django底层到底是如何实现的,本文记录了笔者对django源码的分析过程 I be ...

  6. django(python manage.py imgrate)同步数据库出错后的解决办法

    问题 很多情况下,因为app的models.py的文件内容有误,但是通过python   manage.py    check检查不出来时,当执行python   manage.py    migra ...

  7. python manage.py syncdb Unknown command: 'syncdb'问题解决方法

    在django1.9后的版本中,python manage.py syncdb命令修改为python manage.py migrate,执行正常. 选择sqlite可视化sqlitestudio-3 ...

  8. Python 模型定义 :通过pymysql和数据模型(models.py)创建mysql表及表结构

    一.model的配置 1.创建数据库 2.安装pymysql 3.修改配置文件 数据库连接配置 DATABASES = { 'default': { 'ENGINE': 'django.db.back ...

  9. Django 中 python manage.py makemigrations 与 python manage.py migrate

    执行 python manage.py makemigrations django根据settings.py里面的INSTALLED_APPS项设置找到对应app里的models.py,应用里面创建的 ...

随机推荐

  1. 整合thymeleaf

    1.导入thymeleaf依赖 2.controller类 (1)模板 导入命名空间,xmlns:th="http://www.thymeleaf.org" (2)ModelAnd ...

  2. 新浪sae对storage的文档进行读写操作

    有的人喜欢将一些数据写在服务器的文件里面,并不喜欢存在mysql里,但新浪sae却不支持对本地文件进行操作. 不过sae拓展了一个storage的服务,可以将一些静态文件放在上面.本文不介绍文件的上传 ...

  3. Django自定义分页并保存搜索条件

    Django自定义分页并保存搜索条件 1.自定义分页组件pagination.py import copy class Pagination: def __init__(self, current_p ...

  4. 1254: 盒子游戏(Java)

    WUSTOJ 1254: 盒子游戏 参考博客 叶剑飞Victor的博客 盒子游戏--爱程序网 原理是从上面博客看的,我另外补充了几幅图,方便理解 Description 有两个相同的盒子,其中一个装了 ...

  5. 理解 is_callable

    官方解释: (PHP 4 >= 4.0.6, PHP 5, PHP 7) is_callable — 检测参数是否为合法的可调用结构. 说明 is_callable ( callable $na ...

  6. ASP.NET Core分布式项目-1.IdentityServer4登录中心

    源码下载 一.添加服务端的api 1.添加NUGet包 IdentityServer4 点击下载,重新生成 2.添加Startup配置 打开Startup文件 public class Startup ...

  7. Linux文件删除,但是df -hT之后磁盘空间没有释放

    Linux 磁盘空间总是报警,查到到大文件,删除之后,df看到磁盘空间并没有释放. 查找了下发现系统对rm进行了alias   ,因为Linux对删除操作没有回收站机制,对rm操作进行了自定义,对删除 ...

  8. Binary Table CodeForces - 662C (FWT)

    大意: 给定$nm$大小的$01$矩阵, $1\le n\le 20,1\le m\le 1e5$, 可以任选行列翻转, 求最终$1$总数最少为多少. 显然有$O(m2^n)$的暴力算法 也就是枚举翻 ...

  9. hdu 1002 prime 模板

    Constructing Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  10. eventFlow 系列 <三> 查询所有

    接着上面的例子,产生2条数据.怎么把这两条数据查询出来呢? var commandBus = resolver.Resolve<ICommandBus>(); , ); var execu ...