我是peewee的新手,正在尝试查询配置单元安装使用的mysql metastore db。我可以列出所有可用的表,但无法查询特定的表“tbls”。这是一个标准的metastore表,它只存储metastore中所有表的信息。
这是我的密码截止日期:
from peewee import *
metastore_db = MySQLDatabase("metastore", host="localhost", port=3306, user="root", passwd="")
metastore_db.connect()
tables = metastore_db.get_tables()
for tbl in tables:
print tbl
现在要查询我写的表:
class BaseModel(Model):
class Meta:
database = metastore_db
class TBLS(BaseModel):
DB_ID = IntegerField()
OWNER = CharField()
TBL_NAME = CharField()
class Meta:
db_table = 'TBLS'
tbl = TBLS.select()
for t in tbl:
print t
现在我得到这个错误-
peewee.operationalerror:(1054,“字段列表”中的未知列“t1.id”)
我遗漏了什么,还是因为表名是大写的?我需要提到模型中的所有列吗?
这是tbls表的结构-
mysql> desc TBLS;
+--------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------+------+-----+---------+-------+
| TBL_ID | bigint(20) | NO | PRI | NULL | |
| CREATE_TIME | int(11) | NO | | NULL | |
| DB_ID | bigint(20) | YES | MUL | NULL | |
| LAST_ACCESS_TIME | int(11) | NO | | NULL | |
| OWNER | varchar(767) | YES | | NULL | |
| RETENTION | int(11) | NO | | NULL | |
| SD_ID | bigint(20) | YES | MUL | NULL | |
| TBL_NAME | varchar(128) | YES | MUL | NULL | |
| TBL_TYPE | varchar(128) | YES | | NULL | |
| VIEW_EXPANDED_TEXT | mediumtext | YES | | NULL | |
| VIEW_ORIGINAL_TEXT | mediumtext | YES | | NULL | |
+--------------------+--------------+------+-----+---------+-------+
谢谢您!
====================================================
EDIT: and UPDATE
====================================================
我可以通过添加更多的元信息来删除错误,比如-
class tbls(BaseModel):
tbl_id = PrimaryKeyField(db_column='TBL_ID')
create_time = IntegerField(db_column='CREATE_TIME')
db_id = IntegerField(db_column='DB_ID')
last_access_time = IntegerField(db_column='LAST_ACCESS_TIME')
owner = CharField(max_length=767,db_column='OWNER')
retention = IntegerField(db_column='RETENTION')
sd_id = IntegerField(db_column='SD_ID')
tbl_name = CharField(max_length=128,db_column='TBL_NAME')
tbl_type = CharField(max_length=128,db_column='TBL_TYPE')
class Meta:
db_table = 'TBLS'
tbl = tbls.select()
for t in tbl:
print t.owner,t.tbl_name
现在我可以检索所需的行。我的问题是,如果可能的话,如何获得一个表的所有列而不必显式地命名每个列(如select*)。
暂无答案!
目前还没有任何答案,快来回答吧!