Reputation: 5823
Let's say that I have an existing table that I want to map to that contains 10 columns; however, I only care about writing to 3 of these columns, via a specified Model.
If I insert a record according to this model, the values under columns not included in the Model will result to NULL.
Is there a way in SQLAlchemy to specify the default value of a column to not be NULL? Perhaps 0 for an integer or '' for a string?
Upvotes: 2
Views: 868
Reputation: 7088
Since SQLAlchemy does not know about the columns, you have to setup default values on the server side. Otherwise, specify all the columns and define the default values.
class MyModel(Base):
foo = sa.Column(sa.String, default='bar')
Upvotes: 2