0
创建数据库的问题:烧瓶迁移不会在Heroku的
我无法让我的SQLite数据库在Heroku工作。当我尝试在浏览器中访问该应用的网址时,出现内部服务器错误。 heroku logs
表明这一点:
OperationalError: (sqlite3.OperationalError) no such table: questions [SQL: u'SELECT questions.id AS questions_id, questions.title AS questions_title, questions.content AS questions_content \nFROM questions']
我已经试过:
我可以通过删除我的本地数据库本地重现此错误(没有什么重要的,它尚未):
$ rm data-dev.sqlite
$ heroku local
# Go to localhost:5000 in my browser, 500 Internal server error
OperationalError: (sqlite3.OperationalError) no such table: questions [SQL: u'SELECT questions.id AS questions_id, questions.title AS questions_title, questions.content AS questions_content \nFROM questions']
我可以使用Flask-Migrate的upgrade
命令在本地修复它:
$ python2 manage.py db upgrade
$ heroku local
# Go to localhost:5000, get a working website
然而,当我尝试做同样的事情来修复它在Heroku,这是行不通的:
$ heroku run ls
# Doesn't show any .sqlite database files
$ heroku run python manage.py db upgrade
# Go to the website URL, get 500 Internal server error
$ heroku logs
OperationalError: (sqlite3.OperationalError) no such table: questions [SQL: u'SELECT questions.id AS questions_id, questions.title AS questions_title, questions.content AS questions_content \nFROM questions']
我也尝试手动删除和创建表:
$ heroku run python manage.py shell
>>> db.drop_all()
>>> db.create_all()
>>> quit()
# Go to website URL, get 500 Internal server error
$ heroku logs
OperationalError: (sqlite3.OperationalError) no such table: questions [SQL: u'SELECT questions.id AS questions_id, questions.title AS questions_title, questions.content AS questions_content \nFROM questions']
我很害怕做什么。由于某些原因,Flask-Migrate看起来不会创建数据库文件。我试过manage.py
中的open('textfile.txt', 'w')
,并成功创建了该文件。
你不能在Heroku上使用sqlite。你需要使用一个数据库插件。 –
这样一个简单的答案。我希望我早点知道。谢谢! – joshreesjones