I am using Flask-Migrate (Alembic) to update my database. I updated the models.py file, however I made a mistake. I migrated and went to update the database, however I got this error:
sqlalchemy.exc.IntegrityError: (_mysql_exceptions.IntegrityError) (1215, 'Cannot add foreign key constraint') [SQL: u'\nCREATE TABLE topics (\n\tid INTEGER NOT NULL AUTO_INCREMENT, \n\t`subjectID` INTEGER, \n\ttopic VARCHAR(150) NOT NULL, \n\tPRIMARY KEY (id), \n\tFOREIGN KEY(`subjectID`) REFERENCES subjects (id)\n)\n\n']
What I did was db.Text instead of db.Integer for the foreign key.
When I try to start a new migration, I get the following:
alembic.util.CommandError: Target database is not up to date.
So now I'm stuck. I cannot update the database or migrate. I tried to upgrade to an earlier version of the database using something like this:
python manage.py db downgrade --sql b877018671c:36949b1cca31
But when I run python manage.py db current , I get the latest version of the database I'm stuck in.
Is there a fix for this? Thanks.
source share