Using Flask-Migrate and SQLite3, I am trying to alter column 'confirmed' in table 'user' so that becomes NOT NULLABLE and has a default value of false
. I have updated the existing rows so that confirmed = false
for all of the entries. Though when I try to update the table so that default = False
then I receive the following error:
[SQL: ALTER TABLE user ALTER COLUMN confirmed SET NOT NULL]
(Background on this error at: http://sqlalche.me/e/13/e3q8)
Schema of the table
CREATE TABLE user (
id INTEGER NOT NULL,
username VARCHAR(20) NOT NULL,
email VARCHAR(120) NOT NULL,
image_file VARCHAR(20) NOT NULL,
password VARCHAR(60) NOT NULL, confirmed BOOLEAN, confirmed_on DATETIME,
PRIMARY KEY (id),
UNIQUE (email),
UNIQUE (username)
I have noticed that the latest migrate file from Flask-Migrate does not include the default = false
attribute, even though it should because I have added the code to models.py
:
Models.py:
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
password = db.Column(db.String(60), nullable=False)
posts = db.relationship('Post', backref='author', lazy=True)
batches = db.relationship('Batch', backref='author', lazy=True)
comments = db.relationship('Feedback', backref='author', lazy=True)
#New columns
confirmed = db.Column(db.Boolean, nullable=False, default=False)
confirmed_on = db.Column(db.DateTime, nullable=True)
This is the migration file generated by flask-migrate:
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('user', 'confirmed',
existing_type=sa.BOOLEAN(),
nullable=False)
However, when I manually edit this file so that it includes default = False
, i.e.:
op.alter_column('user', 'confirmed',
existing_type=sa.BOOLEAN(),
nullable=False, default=False)
Then I still receive the same error. (I have also tried editing the migrate file so that the default=false
change is a new entry).
Hopefully that makes sense, I am confused and feel like I have hit a wall.