2016-03-07 279 views
1

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

這是我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網絡基礎教程,它的工作我的本地機器上。但是,我無法在服務器上處理它

+0

我遇到同樣的問題。你有沒有解決它? – Layne

+0

@Layne Nope。找不到解決方案 – Alparslan

回答

0

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

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)