推荐学习书目
› 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 · Jul 7, 2020 · 2163 views
    This topic created in 2271 days ago, the information mentioned may be changed or developed.

    建立表的时候是使用了 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 replies  •  2020-07-07 17:13:58 +08:00
    xiaolinjia
        1
    xiaolinjia  
       Jul 7, 2020
    blank=True 不就好了。null=True 不建议用在 CharField 里
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2561 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:34 · PVG 20:34 · LAX 05:34 · JFK 08:34
    ♥ Do have faith in what you're doing.