添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hi all, this is a duplicate question, but all the duplicates were posted a long time ago and don't seem to have the correct solution.

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file (Background on this error at: http://sqlalche.me/e/13/e3q8)

I am getting this error which the link says is due to an error on pythonanywhere's end, but I am wondering if there is anything on my end I can do to fix this. The reason I am making a duplicate is because there are multiple forum posts that were all replied to with the same solution, to check the file path given for the db, which anyone with this error has already done, otherwise they would get the error "this table does not exist." Prior to getting this error, I fixed that one with this line of code

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///home/robertgrahamky/mysite/database.db'
              

You have a typo in the setting -- there should be 4 slashes after the colon, i.e.

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////home/robertgrahamky/mysite/database.db'

See: https://flask-sqlalchemy.palletsprojects.com/en/2.x/config/#configuration-keys

I changed the code to include 4 ////, but it behaved in the same way. The database file is recognized, but I get this error

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: menu_item_model
[SQL: SELECT menu_item_model.id AS menu_item_model_id, menu_item_model.name AS menu_item_model_name, menu_item_model.description AS menu_item_model_description, menu_item_model."descripción" AS "menu_item_model_descripción", menu_item_model.price AS menu_item_model_price, menu_item_model.image AS menu_item_model_image 
FROM menu_item_model]``

This api works on my local machine and heroku, the only thing I changed was that I installed cors and changed the path to the db file. I ran the db.createAll() command from this website, then I also installed cors using the bash console on this site. Were there some other commands I was supposed to run in the bash console to install my other requirements? Beyond that what should I do to work through this issue?

Did you see any output when you run db.create_all()? You can start a Python console, import db and the class where you define table menu_item_model from your application and check if it exists in the database. You may follow the examples from [the documentation] (https://flask-sqlalchemy.palletsprojects.com/en/2.x/quickstart/#a-minimal-application)

The solution to my problem was to delete my db and run db.create_all() followed by db.session.commit(). The reason the db file was not working was simply because I left out the db.session.commit()

Thanks for your help pafk; that last post did it for me

Sorry, we have had to rate-limit your feedback sending.
Please try again in a few moments... Thanks for the feedback! Our tireless devs will get back to you soon.