我是 Python 新手,我需要你的帮助。我有一台 Mac 并使用 python 3。使用 SublimeText,这是我在运行代码时收到的信息==> 我收到此错误:
NameError: name '__tablename__' is not defined
提前谢谢您!!!
我的整个代码是:
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import create_engine
engine = create_engine('sqlite:///:memory:', echo=True)
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
#creare de tabela
from sqlalchemy import Column, Integer, String
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
fullname = Column(String)
program = Column(String)
aka = Column(String)
adresa = Column(String)
city = Column(String)
state = Column(String)
country = Column(String)
postalcode = Column(String)
def __repr__(self):
return "<User(name='%s', fullname='%s', program='%s', aka='%s',adresa='%s',city='%s',country='%s',postalcode='%s',)>" %(
self.name, self.fullname, self.program, self.aka, self.adresa, self.city, self.state, self.country,self.postalcode)
#creare de tabela
User.__tablename__
table('users', MetaData(bind=None),
Column('id', Integer(),table=(users), primary_key=True, nullable=False),
Column('name', String(), table=(users)),
Column('fullname', String(), table=(users)),
Column('program', String(), table=(users)),
Column('aka', String(), table=(users)),
Column('adresa', String(), table=(users)),
Column('city', String(), table=(users)),
Column('state', String(), table=(user)),
Column('country', String(), table=(users)),
Column('postalcode', String(), table=(users), schema=None))