Hi Miguel,
I just added the following line to my model.
customerComment = db.Column(db.String(500), nullable=False, default="")
The resulting line in my migration script is
op.add_column('angebot', sa.Column('customerComment', sa.String(length=500), nullable=False))
There is no default value, which leads to the following error:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) Cannot add a NOT NULL column with default value NULL [SQL: 'ALTER TABLE angebot ADD COLUMN "customerComment" VARCHAR(500) NOT NULL'] (Background on this error at: http://sqlalche.me/e/e3q8)
Even stranger, I have a field
country = db.Column(db.String(2), nullable=False, default="DE")
and the resulting script line is
op.add_column('user', sa.Column('country', sa.String(length=2), nullable=False))
Am I doing something wrong? Should I use a different default value?
Thanks for your work!
The default value is something that is done at the SQLAlchemy level. If you want the database to insert the default value, use server_default.
Thank you.
Most helpful comment
The
defaultvalue is something that is done at the SQLAlchemy level. If you want the database to insert the default value, useserver_default.