簡體   English   中英

SQLAlchemy sqlite3.operational錯誤

[英]SQLAlchemy sqlite3.operational error

我正在遠程ubuntu服務器上開發flask項目。我也使用SQLAlchemy 但是,當我嘗試運行此腳本時,出現sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file錯誤。

這是我的models.py

import sys
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine

Base = declarative_base()

class Puppy(Base):
    __tablename__ = 'puppy'


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

    @property
    def serialize(self):
       """Return object data in easily serializeable format"""
       return {
           'id': self.id,
           'name': self.name,
           'description' : self.description
       }

engine = create_engine('sqlite:///puppies.db')
Base.metadata.create_all(engine)

我遵循了Udacity Fullstack Web基礎教程,該教程在我的本地計算機上有效。 但是,我無法在服務器上處理它

路徑可能無法正確解析。 嘗試:

import os
import sys
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine

BASE_DIR = os.path.abspath(os.path.dirname(__file__))
DATABASE_PATH = os.path.join(BASE_DIR, 'puppies.db')

Base = declarative_base()

class Puppy(Base):
    __tablename__ = 'puppy'


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

    @property
    def serialize(self):
       """Return object data in easily serializeable format"""
       return {
           'id': self.id,
           'name': self.name,
           'description' : self.description
       }

engine = create_engine('sqlite:///' + DATABASE_PATH)
Base.metadata.create_all(engine)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM