python table类_python – 类没有指定表或tablename,不会从现有的表映射类继承

在尝试使用Python Flask-SQLAlchemy框架创建UserRemap表时遇到错误,错误信息提示类没有指定__table__或__tablename__。尽管定义了数据库字段,但模型未正确继承已有表映射类。解决方案可能包括为类添加__tablename__属性或确保正确继承自db.Model。
摘要由CSDN通过智能技术生成

当我试图添加一个新的表到

Python /烧瓶 –

class UserRemap(db.Model):

name = db.Column(db.String(40))

email = db.Column(db.String(255))

password = db.Column(db.String(64))

flag = db.Column(db.String(1))

def __init__(self, name, email, password):

self.email = email

self.name = name

self.password = password

self.flag='N'

这里是表模式 –

mysql> desc UserRemap;

+----------+--------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+----------+--------------+------+-----+---------+-------+

| name | varchar(40) | NO | | NULL | |

| password | varchar(64) | NO | | NULL | |

| email | varchar(255) | NO | | NULL | |

| flag | char(1) | NO | | N | |

+----------+--------------+------+-----+---------+-------+

4 rows in set (0.00 sec)

当我去互动python shell并且从myapp导入db;我收到这个错误消息,

from server import db; Traceback (most recent call last): File

"", line 1, in File "server.py", line 74, in

class UserRemap(db.Model):

File "/usr/lib/python2.7/site-packages/Flask_SQLAlchemy-0.15-py2.7.egg/flaskext/sqlalchemy.py",

line 467, in __init__

DeclarativeMeta.__init__(self, name, bases, d)

File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.5-py2.7-linux-i686.egg/sqlalchemy/ext/declarative.py",

line 1336, in __init__

_as_declarative(cls, classname, cls.__dict__)

File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.5-py2.7-linux-i686.egg/sqlalchemy/ext/declarative.py",

line 1261, in _as_declarative

"table-mapped class." % cls sqlalchemy.exc.InvalidRequestError: Class does not have a __table__ or

__tablename__ specified and does not inherit from an existing table-mapped class.

关于如何解决这个问题的任何想法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值