Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot complete Flask-Migration

I've setup a local Postgres DB with SQLAlchemy and cannot commit my first entry. I keep on getting this error...

ProgrammingError: (ProgrammingError) relation "user" does not exist
LINE 1: INSERT INTO "user" (name, email, facebook_id, facebook_token...

It seems like the fields aren't matching to those in the database. I'm trying to migrate using flask-migrate but, when I run $ python app.py db migrate I get this error...

raise util.CommandError("No such revision '%s'" % id_)
alembic.util.CommandError: No such revision '39408d6b248d'

It may be best to delete everything and start from scratch as it seems I have botched my database setup and / or migration but I'm not sure how to.

UPDATE: The database has started working now (I dropped and created it again). However, I'm still getting the same error trying to run migrations and it turns out the "no such revision '39408d6b248d' is referring to a migration from an unrelated project. I re-installed flask-migrate but same error.

like image 955
Suraj Kapoor Avatar asked Jan 07 '14 13:01

Suraj Kapoor


People also ask

How do you migration in a flask?

The contents of this folder need to be added to version control along with your other source files. You can then generate an initial migration: $ flask db migrate -m "Initial migration." The migration script needs to be reviewed and edited, as Alembic currently does not detect every change you make to your models.

How do I reset my alembic migrations?

Go to versions/ inside migrations/ . Type flask db migrate again. Should work.


2 Answers

flask-migrate will create a table named "alembic_version" in your database.
so you should drop this table and delete migrations folder in your project.
and then use $ python app.py db init again...
I think $ python app.py db migrate will work fine.

like image 178
Cello Hsueh Avatar answered Sep 27 '22 20:09

Cello Hsueh


Alembic keeps the migration history in your database, this is why it still recognises there is another revision there. I keep my project on Heroku so I was able to just do heroku pg:pull ... to be able to get a new copy of my database. Prior to this you will have to drop your local db. In case you don't want to drop your local, I think dropping the table should work too. I use the PG Commander as a GUI tool to quickly browse my databases.

like image 34
lawicko Avatar answered Sep 27 '22 20:09

lawicko