mardi 19 mai 2015

Get sqlite3.OperationalError: unable to open database file after locally run via Pycharm

I have created and populated a sqllite database in a Python + Flask app.

When I run the DBHandl.getData() in my console, I get the data.

But when I use Pycharm to run the app at localhost:5000 I can not connect and get this error:

OperationalError: (sqlite3.OperationalError) unable to open database file

None of the usual errors aply. No funny charakters, no access-restrictions, no typos. As I said, data-access WORKS in my console.

from flask import Flask, render_template
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker

app = Flask(__name__)

Base = declarative_base()
engine = create_engine("sqlite:///temp/database.db")
DBSession = sessionmaker(bind=engine)
session = DBSession()

class Person(Base):
    __tablename__ = "person"

    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)

    def __repr__(self):
        return 'Name = %s, ID = %s' % (self.name, self.id)

class Address(Base):
    __tablename__ = "address"

    id = Column(Integer, primary_key=True)
    street = Column(String)
    person_id = Column(Integer, ForeignKey("person.id"))
    person = relationship(Person)

    def __repr__(self):
        return 'Street= %s, Person_ID = %s' % (self.street, self.person_id)

class DBHandl():
    @classmethod
    def getData(self):  # Return Personen + Adressen
        q = session.query(Person, Address).filter(Person.id == Address.person_id).all()
        return q

@app.route('/')
def hello_world():
    #liste=["1","2"]
    q = DBHandl.getData()
    return render_template("home.html")


if __name__ == '__main__':
    app.run(debug=True)

Aucun commentaire:

Enregistrer un commentaire