SQLAlchemy and empty columns SQLAlchemy and empty columns python python

SQLAlchemy and empty columns


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)

SQLAlchemy docs for Tables and Columns, excerpt from v1.2 doc:

nullable – When set to False, will cause the “NOT NULL” phrase to be added when generating DDL for the column. When True, will normally generate nothing (in SQL this defaults to “NULL”), except in some very specific backend-specific edge cases where “NULL” may render explicitly. Defaults to True unless primary_key is also True, in which case it defaults to False. This parameter is only used when issuing CREATE TABLE statements.


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


In case the default are declared in the schema (but with a NOT NULL check), you can declare them with a FetchedValue

from sqlalchemy.schema import FetchedValueclass Foo(Base):    date_created = Column(DateTime, server_default=FetchedValue())