views:

261

answers:

2

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
+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)

See SQLAlchemy docs for Tables and Columns

Van Gale