AttributeError: type object 'User' has no attribute 'query'

import os
import sys
from sqlalchemy import Column, ForeignKey, Integer, String, DateTime, Boolean, Float, Date, Table
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
from flask_security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin, login_required

Base = declarative_base()

roles_users = Table('roles_users', Base.metadata, Column('user_id', Integer, ForeignKey('user.id')), Column('role_id', Integer, ForeignKey('role.id')))

class Role(Base, RoleMixin):
    __tablename__ = 'role'
    id = Column(Integer, primary_key=True)
    name = Column(String(80), unique=True)
    description = Column(String(255))

class User(Base, UserMixin):
    __tablename__ = 'user'

    id = Column(Integer, primary_key=True)
    email = Column(String(250), nullable=False)
    password = Column(String(30))
    last_login_at = Column(DateTime)
    active = Column(Boolean)
    confirmed_at = Column(DateTime)
    current_login_at = Column(DateTime)
    last_login_ip = Column(String(45))
    current_login_ip = Column(String(45))
    login_count = Column(Integer)

3
1
Krish 100200 points

                                    from decouple import config
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session, declarative_base
from types import SimpleNamespace

SQLALCHEMY_DATABASE_URL = config('SQLALCHEMY_DATABASE_URL')
engine = create_engine(SQLALCHEMY_DATABASE_URL)
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)

session = scoped_session(Session)
Base = declarative_base()
# Note the line below
Base.query = session.query_property()


class User(Base):
    __tablename__ = 'user'

    id = Column(Integer, primary_key=True)
    email = Column(String(250), nullable=False)
    password = Column(String(30))
    last_login_at = Column(DateTime)
    active = Column(Boolean)
    confirmed_at = Column(DateTime)
    current_login_at = Column(DateTime)
    last_login_ip = Column(String(45))
    current_login_ip = Column(String(45))
    login_count = Column(Integer)

3 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
'RawQuerySet' object has no attribute 'username' type object has no attribute 'username_field' type object 'User' has no attribute 'USERNAME_FIELD' AttributeError: type object 'Person' has no attribute 'USERNAME_FIELD' AttributeError: type object 'Customer' has no attribute 'USERNAME_FIELD' AttributeError: type object 'User' has no attribute 'query' sqlalchemy AttributeError: type object 'User' has no attribute 'query' AttributeError: type object has no attribute 'USERNAME_FIELD' sqlalchemy AttributeError: type object 'User' has no attribute 'get_query' AttributeError at , 'method' object has no attribute 'user' QuerySet' object has no attribute 'username' 'ClientUser' object has no attribute 'create_dm' AttributeError: type object 'a' has no attribute 'username' 'QuerySet' object has no attribute 'User' 'QuerySet' object has no attribute 'username' AttributeError: type object 'User' has no attribute 'USERNAME_FIELD' type object 'User' has no attribute 'query' declarative_base AttributeError: type object 'User' has no attribute 'get' type object ' has no attribute 'query' object type table has no attribute query type object 'User' has no attribute 'objects' AttributeError: 'Praetorian' object has no attribute 'user class' type object 'User' has no attribute 'get' django 'QuerySet' object has no attribute AttributeError: 'Praetorian' object has no attribute 'user_class' AttributeError: 'Tweet' object has no attribute 'user' snscrape 'User' object has no attribute 'name' django orm has no attribute query 'function' object has no attribute 'user' queryset' object has no attribute 'user' AttributeError: type object 'Service' has no attribute 'query type object 'Employee' has no attribute 'query' AttributeError: type object 'Session' has no attribute 'query' AttributeError: type object 'Order_and_customer' has no attribute 'query python AttributeError: module 'app.models.User' has no attribute 'query' AttributeError: type object 'Brand' has no attribute 'query' Base type object 'User' has no attribute 'query' type object 'DBSession' has no attribute 'connect' sqlalchemy session has no attribute 'query'
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source