SQLAlchemy + Mariadb freezes on initialization

61
January 31, 2022, at 09:10 AM

I'm converting my program to SQLAlchemy, was using pymysql connector before and everything was working as it should, right now it just freeze on metadata creation, everything looks like this:

main file:

import db_connection
db_connection.Base.metadata.create_all(bind=db_connection.engine)  # freezes right here

db_connection.__init__:

from .database import SessionInstance, engine
from .schema import *
from .crud import *
from .model import *

db_connection.database:

import os
from sshtunnel import SSHTunnelForwarder
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from dotenv import load_dotenv
load_dotenv()
tunnel = SSHTunnelForwarder(
        (os.getenv('server_ip'), 22),
        ssh_username=os.getenv('ssh_username'),
        ssh_password=os.getenv('ssh_password'),
        remote_bind_address=("localhost", 3306)
)
tunnel.start()
engine = create_engine("mariadb+mariadbconnector://{user}:{password}@{ip}:{port}/{db_name}".format(
    user=os.getenv('db_user'),
    password=os.getenv('db_password'),
    ip=os.getenv('db_ip', '127.0.0.1'),
    port=tunnel.local_bind_port,
    db_name=os.getenv('db_name', 'Vocal')
))
SessionInstance = sessionmaker(autoflush=False, autocommit=False, bind=engine)
Base = declarative_base()

And the db_connection.schema

from sqlalchemy import Column, String, Integer, ForeignKey
from sqlalchemy.orm import relationship
from db_connection.database import Base

class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True, autoincrement=True)
    username = Column(String, not_null=True)
    password_hash = Column(String, not_null=True)
    email = Column(String, not_null=True)
    bal = relationship('Bank', back_populates='user')

Also the dependency tree:

I tried without defining it as a library, but it didn't work as well, and I believe it's more organized like that

READ ALSO
How to update a CSS Grid without re-rendering a specific component in ReactJS?

How to update a CSS Grid without re-rendering a specific component in ReactJS?

I'm working on a React website with a video player that should continuously play on all routesI'm trying to figure out a way to build a specific dynamic layout using CSS Grid that will update itself and the state of all components except the video component

70
Get user saved in session in EJB with NodeJS

Get user saved in session in EJB with NodeJS

Hi im having problem with express-session, it seems like not saving my user sessionHere is when I declare my session

70
Revslider jQuery "Long-From-Top" not working

Revslider jQuery "Long-From-Top" not working

i have a revslider and want to have a long-from-top but it still looks like a short-from-top

80
How can I check if the player is in a boat? [closed]

How can I check if the player is in a boat? [closed]

Want to improve this question? Update the question so it's on-topic for Stack Overflow

73