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