1

I am building a flask application over an already existing database so there was no need to declare the whole models fully. 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:

.__dict__ 

only returns the first 4 columns. i have tried using filter and also filter by but data returned only contains the first 4 columns. Here is my query:

users = Users.query.filter(
    section_serial == sectionserial
).all()

I am using the postgres database. 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. I cannot get the rest of the columns

4
  • 1
    Please provide a minimal reproducible example. Start by including your table schema as seen by PostgreSQL. Then make it very clear what you mean by "only returns the first 4 columns" using example data and output. Include a sample of expected output as well. Commented May 1, 2020 at 13:37
  • Hello, i have provided the schema. Hope it will be helpful Commented May 1, 2020 at 16:46
  • @snakecharmerb sorry i had left it out by mistake Commented May 1, 2020 at 17:08
  • @snakecharmerb what if i had already declared my_users in another model. I have noted in the other model i had just declared the four columns i get. I think that is the problem Commented May 1, 2020 at 17:09

1 Answer 1

1

The problem was it was conflicting with a login model i had created though with a different name. 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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.