python
Add column to existing table with default value SQLAlchemy
When you are changing your table structure and adding a new column to it. Then to make it nullable false you have to assign a default value to it. But you can not do that by only adding default attribue. You have to use server_default for this purpose.
from sqlalchemy import text
class User_Model(db.Model):
#use server_default if table already created to add default value
flag = db.Column(db.Boolean, nullable=False, server_default=text('1'))
Was this helpful?
Similar Posts
- [Pandas] Add new column to DataFrame based on existing column
- Insert new column with default value in Pandas DataFrame
- Add new row to an existing Pandas DataFrame
- Get highest id or value record from a column SqlAlchemy Query
- [Python] Default value of function argument
- Create table model using SQLAlchemy
- SQLAlchemy query to get distinct records from table