flask-migrate

Flask-migrate: change model attributes and rename corresponding database columns

折月煮酒 提交于 2021-02-10 12:38:07
问题 I have a bit of experience with Flask but not very much with databases (Flask-migrate / alembic / SqlAlchemy). I'm following this tutorial and things are working quite alright. I have a User model like this: # user_model.py from app import DB ... other imports class User(UserMixin, DB.Model): __tablename__ = 'users' id = DB.Column(DB.Integer, primary_key=True) username = DB.Column(DB.String(64), index=True, unique=True) email = DB.Column(DB.String(120), index=True, unique=True) password_hash

Flask-migrate: change model attributes and rename corresponding database columns

给你一囗甜甜゛ 提交于 2021-02-10 12:37:06
问题 I have a bit of experience with Flask but not very much with databases (Flask-migrate / alembic / SqlAlchemy). I'm following this tutorial and things are working quite alright. I have a User model like this: # user_model.py from app import DB ... other imports class User(UserMixin, DB.Model): __tablename__ = 'users' id = DB.Column(DB.Integer, primary_key=True) username = DB.Column(DB.String(64), index=True, unique=True) email = DB.Column(DB.String(120), index=True, unique=True) password_hash

SQLAlchemy + alembic: create schema migration

喜欢而已 提交于 2020-08-24 06:04:50
问题 I'm not sure how to define a create schema foo migration? My Model looks like this (I'm using Flask-Migrate): class MyTable(db.Model): __tablename__ = "my_table" __table_args__ = {"schema": "foo"} id = ColumnPrimKey() name = Column(Text, unique=True, nullable=False) When I execute mange db upgrade I get a failure because the schema "foo" does not exist. How can I add a migration for the schema with SQLAlchemy and Alembic? 回答1: I accomplished this by modifying the migration upgrade command to

SQLAlchemy + alembic: create schema migration

江枫思渺然 提交于 2020-08-24 06:04:48
问题 I'm not sure how to define a create schema foo migration? My Model looks like this (I'm using Flask-Migrate): class MyTable(db.Model): __tablename__ = "my_table" __table_args__ = {"schema": "foo"} id = ColumnPrimKey() name = Column(Text, unique=True, nullable=False) When I execute mange db upgrade I get a failure because the schema "foo" does not exist. How can I add a migration for the schema with SQLAlchemy and Alembic? 回答1: I accomplished this by modifying the migration upgrade command to

Flask-Migrate sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column

不打扰是莪最后的温柔 提交于 2020-07-18 04:02:29
问题 I am using Flask-Migrate in my application, with the following models: listpull/models.py from datetime import datetime from listpull import db class Job(db.Model): id = db.Column(db.Integer, primary_key=True) list_type_id = db.Column(db.Integer, db.ForeignKey('listtype.id'), nullable=False) list_type = db.relationship('ListType', backref=db.backref('jobs', lazy='dynamic')) record_count = db.Column(db.Integer, nullable=False) status = db.Column(db.Integer, nullable=False) sf_job_id = db

models are not detectable by flask migrate

做~自己de王妃 提交于 2020-06-27 22:12:13
问题 I have this tree in my flask application: -- api -- migrations -- model -- __init__.py -- Persons.py -- Comments.py -- other_classes.py -- resources -- __init__.py -- app.py -- util.py This is __init_.py from model directory: from os.path import dirname, basename, isfile import glob modules = glob.glob(dirname(__file__)+"/*.py") __all__ = [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')] from .Persons import Persons This is util.py from flask import Flask

Flask-Migrate No Changes Detected to Schema on first migration

别说谁变了你拦得住时间么 提交于 2020-05-25 05:00:05
问题 I'm using Flask with Flask-SQLAlchemy and Flask-Migrate to create an application, however when I try to create a migration nothing happens. I've created two tables in app/models.py : from flask import current_app from . import db class Student(db.Model): __tablename__ = 'students' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(64), unique=True, nullable=False) password_hash = db.Column(db.String(128)) def __init__(self, **kwargs): super(Student, self).__init__(*

How to sync db with Flask-Migrate in a fresh application deployment?

佐手、 提交于 2020-05-15 07:45:36
问题 When deploying an application to a fresh server (i.e. the database is empty) how do I sync the database properly with Flask-Migrate? I've added Flask-Migrate to the project when I already had some schema in place so I don't have "initial" migrations with all create_table() . Now when I do manage.py db upgrade in my deployment script I get relation "..." does not exist . Is there any built-in way to detect empty database and run 'create_all()' instead of migrations? This is what the Alembic's

Flask database migrations on heroku

你离开我真会死。 提交于 2020-05-10 06:26:19
问题 With my app I am using flask-script and flask-migrate for database migrations, everything works locally. When, I run heroku run python manage.py db init It creates this output: Running python manage.py db init on ⬢ fpds-scheduler... up, run.1290 (Free) Creating directory /app/migrations ... done Creating directory /app/migrations/versions ... done Generating /app/migrations/README ... done Generating /app/migrations/script.py.mako ... done Generating /app/migrations/alembic.ini ... done

Flask database migrations on heroku

二次信任 提交于 2020-05-10 06:24:07
问题 With my app I am using flask-script and flask-migrate for database migrations, everything works locally. When, I run heroku run python manage.py db init It creates this output: Running python manage.py db init on ⬢ fpds-scheduler... up, run.1290 (Free) Creating directory /app/migrations ... done Creating directory /app/migrations/versions ... done Generating /app/migrations/README ... done Generating /app/migrations/script.py.mako ... done Generating /app/migrations/alembic.ini ... done