My flask app works absolutely well locally. I am deploying the app to Python Anywhere. The problem is that when I run flask db upgrade in the pythonanywhere bash I get the error below (when I do any db migration and upgrade locally there are no errors):
sqlalchemy.exc.IntegrityError: (_mysql_exceptions.IntegrityError)
(1215, 'Cannot add foreign key constraint') [SQL: '\nCREATE TABLE
comments (
\n\tid INTEGER NOT NULL AUTO_INCREMENT, \n\tbody TEXT, \n\ttimestamp
DATETIME, \n\tdisable BOOL, \n\tauthor_id INTEGER, \n\tpost_id
INTEGER, \
n\tPRIMARY KEY (id), \n\tFOREIGN KEY(author_id) REFERENCES users
(id), \n\tFOREIGN KEY(post_id) REFERENCES posts (id), \n\tCHECK
(disable IN (
0, 1))\n)\n\n']
I have checked other similar questions and known the possible sources of this error but I don't see any of the problems mentioned. Here is the comments model:
class Comment(db.Model):
__tablename__ = 'comments'
id = db.Column(db.Integer, primary_key=True)
body = db.Column(db.Text)
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
disable = db.Column(db.Boolean)
author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
post_id = db.Column(db.Integer, db.ForeignKey('posts.id'))