0

Having a tough time getting Flask-migrate to detect new column in a table. My guess is that something isn't getting imported, or I'm importing things in the incorrect order.

The app is instantiated by a __init__.py file. The overall directory of the app is structured as such:

|-static/
|-templates/
|__init__.py
|filters.py
|models.py
|forms.py
|utils.py
|views.py

The relevant part of the __init__.py file looks like this:

# Import flask and template operators
from flask import Flask, render_template, Blueprint
import os
# Import SQLAlchemy
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_uploads import UploadSet, configure_uploads
from flask_mail import Mail
# Define the WSGI application object
app = Flask(__name__)

# Configurations
app.config.from_pyfile(os.path.join('..','config.py'))

# Define the database object which is imported
# by modules and controllers
db = SQLAlchemy(app)
from . import models
migrate = Migrate(app, db,compare_type=True)

mail = Mail(app)

In the command line I set export FLASK_APP=<app_name>

I make the change to the models.py file, adding a new column to one of my tables.

Then I run the command flask db migrate

However the only output I get from the above command is:

INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.

And there is no new migration script added to the versions directory of the migrations folder. This has worked in the past and I'm not sure why it's no longer working.

themantalope
  • 1,040
  • 11
  • 42

2 Answers2

1

For someone who may be struggling with this problem, a couple things I did to help:

1) upgrade to the latest version of flask-migrate. this fixed (most) of the issues for me.

2) if you have old migrations, move them to a new folder (eg mv migrations/ migrations_old) and then re-init migrations with flask db init. Then make the changes you want to the database, and check that the new migration script was correctly created.

Of course, no guarantees that this will work though. I still never figured out the root issue for my case but these two steps worked.

themantalope
  • 1,040
  • 11
  • 42
0

I had this issue when there is an existing migration that I had not deployed yet. After running flask db upgrade, then flask-migrate was able to detect the new column.

amucunguzi
  • 1,203
  • 1
  • 12
  • 16