sqlite – SQLAchemy中的ProgrammingError线程错误

前端之家收集整理的这篇文章主要介绍了sqlite – SQLAchemy中的ProgrammingError线程错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在sqlite db中有两个简单的表.

from sqlalchemy import MetaData,Table,Column,Integer,ForeignKey,\
    create_engine,String
from sqlalchemy.orm import mapper,relationship,sessionmaker,scoped_session
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('sqlite:///dir_graph.sqlite',echo=True)

session_factory = sessionmaker(bind=engine)
Session = scoped_session(session_factory)
session = Session()

Base = declarative_base()

class NodeType(Base):
    __tablename__ = 'nodetype'
    id = Column(Integer,primary_key=True)
    name = Column(String(20),unique=True)
    nodes = relationship('Node',backref='nodetype')

def __init__(self,name):
    self.name = name

def __repr__(self):
    return "Nodetype: %s" % self.name


class Node(Base):
    __tablename__ = 'node'

    id = Column(Integer,unique=True)
    type_id = Column(Integer,ForeignKey('nodetype.id'))


    def __init__(self,_name,_type_id):
        self.name = _name
        self.type_id = _type_id

Base.Metadata.create_all(engine)

在运行之后,我与解释器交互.例如n1 =节点(‘Node1’,1)以了解sqlalchemy.在我做了session.com()并尝试另一个语句之后,例如n2 = Node(‘n2’,1)我收到此错误
sqlalchemy.exc.ProgrammingError

猜你在找的Sqlite相关文章