Issue
I have a fairly large Flask app, and my typical workflow to create new data tables is as follows:
I create a class in models.py, such as the below:
class ExampleModel(db.Model):
__tablename__ = 'example_table'
id = db.Column(db.Integer, primary_key=True)
text = db.Column(db.String(100))
Then I run flask db migrate
and flask db upgrade
. After these commands, the table is created and I can insert data normally
item = ExampleModel(text='something')
db.session.add(item)
db.session.commit()
Up until now I've had no problems using the above workflow, even immediately before I started having issues. I added a table, and then added some columns to it, and basically just ran into trouble with the nullable values and whatnot (user error). I didn't do much other than delete some model classes, migration scripts, and manually deleted a table in psql (I am using Postgres).
Now, I am unable to execute a test case (ExampleModel) from above. When I try this simple example, no migration script is created in the migrations directory
Output from flask db migrate
:
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
Output from flask db upgrade
:
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
Things I've tried:
- Rebasing from master, essentially starting over
- Using the test model above
- Deleting
migrations
directory and creating a new one
My config and init files should be fine- they are unchanged since this was last working. I'm stumped on this one
Solution
After a bit I was able to get it working. This is what I did:
- Deleted alembic_version table from my db (DROP)
- Made a new alembic_version table with
flask db stamp head
From there I was able to add tables using the typical workflow.
I'm leaving this open because I'm not sure that the above is actually the correct approach to solve- I may have done something else while I was working on it
Answered By - Dr. Funkenstein
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.