[英]flask sql alchemy model (autoloaded) not getting all columns in table
I am building a flask application over an already existing database so there was no need to declare the whole models fully.我正在现有数据库上构建 flask 应用程序,因此无需完全声明整个模型。 I have this table:
我有这张桌子:
class Users(db.Model):
__tablename__ = 'my_users'
__table_args__ = {
'autoload': True,
'autoload_with': db.engine
}
the table has about 10 columns but when i query the data i can see that the attribute:该表大约有 10 列,但是当我查询数据时,我可以看到该属性:
.__dict__
only returns the first 4 columns.仅返回前 4 列。 i have tried using filter and also filter by but data returned only contains the first 4 columns.
我尝试使用过滤器并过滤,但返回的数据仅包含前 4 列。 Here is my query:
这是我的查询:
users = Users.query.filter(
section_serial == sectionserial
).all()
I am using the postgres database.我正在使用 postgres 数据库。 Here is a minimal example:
这是一个最小的例子:
CREATE TABLE public.my_users
(
user_serial integer NOT NULL DEFAULT nextval('my_users_seq'::regclass),
user_name character varying(16) NOT NULL,
user_password character varying(42) NOT NULL,
id_number character varying(155) NOT NULL,
date_added timestamp without time zone NOT NULL DEFAULT now(),
is_enabled boolean NOT NULL DEFAULT true,
expiry_date date NOT NULL DEFAULT (('now'::text)::date + 30),
phone_number character varying(254),
notes text,
section_serial integer,
full_name character varying(155) NOT NULL,
zip_code boolean NOT NULL DEFAULT false,
CONSTRAINT user_serial_pkey PRIMARY KEY (user_serial)
);
After querying the data i only get user_serial, user_name, user_password and id_number.查询数据后,我只得到 user_serial、user_name、user_password 和 id_number。 I cannot get the rest of the columns
我无法获得列的 rest
The problem was it was conflicting with a login model i had created though with a different name.问题是它与我使用不同名称创建的登录 model 冲突。 I think models should just be declared once.
我认为模型应该只声明一次。
class SystemUsers(db.Model):
__tablename__ = 'my_users'
userserial = db.Column(
'user_serial', db.Integer, primary_key=True)
username = db.Column('user_name ', db.String)
password= db.Column('user_password ', db.String)
idnumber = db.Column('id_number', db.String)
isactive = True
isanonymous = False
authenticated = False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.