0
從SQLAlchemy的文檔:如何`可空= FALSE`工作SQLAlchemy的
可爲空 - 如果設置爲真默認,表示該列將 呈現爲允許NULL,否則它呈現爲NOT NULL 。這個 參數僅在發出CREATE TABLE語句時使用。
我認爲設置nullable=True
爲一個列基本上使該列需要。例如:
class Location(db.Model):
__tablename__ = 'locations'
id = db.Column(db.Integer, primary_key=True)
latitude = db.Column(db.String(50), nullable=False)
...
然而,當我不緯度場創建Location
情況下,我沒有得到一個錯誤!
Python 2.7.8 (default, Oct 19 2014, 16:02:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> Location(latitude=None)
<app.models.Location object at 0x10dce9dd0>
這是怎麼回事?
http://stackoverflow.com/questions/20718469/validation-in-sqlalchemy#comment31059318_20718469 –