python - Error while trying to migrate database (slalchemy, slqite3) -
i have next models.py file:
from app import db, bcrypt sqlalchemy import foreignkey sqlalchemy.orm import relationship class blogpost(db.model): __tablename__ = "posts" id = db.column(db.integer, primary_key=true) title = db.column(db.string, nullable=false) desc = db.column(db.string, nullable=false) author_id = db.column(db.integer, foreignkey('users.id')) def __init__(self, title, desc): self.title = title self.desc = desc def __repr__(self): return "titulo >> " + self.title class user(db.model): __tablename__ = 'users' id = db.column(db.integer, primary_key=true) name = db.column(db.string, nullable=false) email = db.column(db.string, nullable=false) password = db.column(db.string, nullable=false) posts = relationship("blogpost", backref="author") def __init__(self, name, email, password): self.name = name self.email = email self.password = password def __repr__(self): return "usuario >> ", self.name then ran:
python manage.py db init and fine, thing when tried modify models file make migration.. change line:
self.password = password to:
self.password = bcrypt.generate_password_hash(password) and when ran:
python manage.py db migrate it works, when tried upgrade with:
python manage.py db upgrade i next error:
"no support alter of constraints in sqlite dialect") notimplementederror: no support alter of constraints in sqlite dialect note: database has few records testing.. thank you!
alembic has changed how sqlite migrations done since tutorials alembic written. alter commands need use batch mode. mode still compatible other databases, if decide switch sqlite later.
for each table being altered, place operations inside with op.batch_alter_table('table_name'): block.
def upgrade(): op.batch_alter_table('table_name'): op.alter_column(...)
Comments
Post a Comment