-
-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default value not working correctly. #265
Comments
Can you share the code that you used with The |
Hi @miguelgrinberg, thanks for replying. enabled = db.Column(db.Boolean, nullable=False, server_default=True) Here's the stack trace:
|
The |
Should i be using |
you have two options, either set the server default, or else create the column as nullable, then set it to your default using an UPDATE statement, and finally switch it to non-nullable. |
I have close to a hundred millions rows, i guess If it's not too much to ask, how would you describe the server_default as True? Thanks again |
Depends on the database that you are using. |
Thanks, i'll try that. Im closing this issue. |
thanks, that’s help me a lot |
thank you |
IMO, correct way of doing this would be to use enabled = db.Column(db.Boolean, server_default=db.sql.True_()) |
Based on the comments added to the |
Hi @miguelgrinberg.
I'm trying to add flask-migrate to an existing model with data. My first migration is adding a boolean column called enabled with default True.
The upgrade method of the migration is generated as following:
Applying this migration makes enabled with default as False.
Changing the migration to:
op.add_column('prediction', sa.Column('enabled', sa.Boolean(), nullable=False, default=True))
also makes enabled False by default.
Using server_default makes this error appear on
flask db init
:Am i doing something wrong? Thanks
The text was updated successfully, but these errors were encountered: