When I try to insert a new record into the database using SQLAlchemy and I don't fill out all values, it tries to insert them as "None" (instead of omitting them). It then complains about "can't be null" errors. Is there a way to have it just omit columns from the sql query if I also omitted them when declaring the instance?
+7
A:
This is a database schema issue, not an SQLAlchemy issue. If your database schema has a column which cannot be NULL, you must put something (i.e. not None) into there. Or change your schema to allow NULL in those columns.
Wikipedia has an article about NULL and an article which describes non-NULL constraints
Ali A
2009-02-14 11:26:35
+3
A:
To add to the answer from Ali A, this means you need to have nullable=True in your column definition, so that NULL is allowed in the column.
For example:
email_address = Column(String, nullable=True)
Van Gale
2009-02-14 12:11:20