0

I have a pre coded Sql Alchemy database and the file name is app.db , I wold like to use the same app to get those data to code a fresh flask app , If so how can i do it?

from flask import Flask,render_template,current_app
from flask_sqlalchemy import SQLAlchemy

app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']="sqlite:///app .db"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=False
db=SQLAlchemy(app)

@app.route('/')
def home_page():

    return render_template('index.html')

When I run the above code in my Flask app it creates a new db file but I want to get data from the app.db file which I have already created

  • [Show us](https://stackoverflow.com/help/minimal-reproducible-example) the code you used to create app.db, and the flask code you're trying to access it with. – J_H Apr 01 '23 at 19:02
  • Please provide enough code so others can better understand or reproduce the problem. – Andromeda Apr 01 '23 at 19:38
  • I have updated the code I used as it is specified in the documentation – Mohamed Ali Apr 03 '23 at 09:57

2 Answers2

0

There is an extra space in app .db in this line app.config['SQLALCHEMY_DATABASE_URI']="sqlite:///app .db", I think you need to remove this to get your code working.

Mubashar
  • 40
  • 6
0

here, you should add the absolute path to this file right.

app.config['SQLALCHEMY_DATABASE_URI']="sqlite:///absolute path"

like in the engine of SQLQLCHEMY here

engine = create_engine('sqlite:///C:\\sqlitedbs\\app.db', echo=True)

I guess the sample here helps: sqlalchemy,creating an sqlite database if it doesn't exist

Karen Baghdasaryan
  • 2,407
  • 6
  • 24
Ali Massoud
  • 135
  • 1
  • 10