V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
18870715400
V2EX  ›  Python

关于 sqlite3 的一个问题

  •  
  •   18870715400 · 2020-07-07 16:19:25 +08:00 · 1557 次点击
    这是一个创建于 1412 天前的主题,其中的信息可能已经有所发展或是发生改变。

    建立表的时候是使用了 django 的 model 来建立表,数据库选择 sqlite3

    anum = models.CharField(max_length=50, default='')
    
    # 但是在 sql 语句插入的时候却报了一个错,
    
    # sqlite3.IntegrityError: NOT NULL constraint failed: table.anum
    
    # 但是在建表的时候不是设置了默认值么, 为什么还是需要 anum 这个字段,另外, 使用 mysql 插入数据的时候不会报这个错误, 难道非要加个 null=True 么, 另外使用 sqlite3 时候加上 null=True 如果 insert 的时候不传值就会默认为 null,default 的值就会没用了,那么应该怎么解决呢
    
    1 条回复    2020-07-07 17:13:58 +08:00
    xiaolinjia
        1
    xiaolinjia  
       2020-07-07 17:13:58 +08:00
    blank=True 不就好了。null=True 不建议用在 CharField 里
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   823 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:34 · PVG 04:34 · LAX 13:34 · JFK 16:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.