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.
It means that the entry in table
alembic_version
of your db is "39408d6b248d" and there's no migration file related to it in migrations folder (by defaultmigrations/versions
).So better drop the table
alembic_version
from your db and do$ python app.py db history
to get the new head of migrations, say, 5301c31377f2Now run
$ python app.py db stamp 5301c31377f2
to let alembic know that it's your migration head (which gets stored in tablealembic_version
).