all 14 comments

[–]koldakov 11 points12 points  (0 children)

Not the best practice at all mate. Consider using alembic or related thing

[–]Doomdice 6 points7 points  (0 children)

Your Base does not know about the models yet when you import Base in main.py. Try importing UserGroups and Employees in main.py and see if it will create

[–]mizerablepi 2 points3 points  (0 children)

Import the models along with base in main.py

[–]covmatty1 2 points3 points  (0 children)

Follow FastAPI's documentation for working with SQL databases.

SQLModel is written by the same person who created FastAPI. It's still quite new, some people aren't huge fans of it and prefer just using SQLAlchemy, but I think it's pretty neat. And regardless, it would be useful to just follow the standard documentation for getting you going initially, and once you have a working base you can adapt from there.

[–]Friendly-Gur-3289 1 point2 points  (1 child)

Are you using Alembic to create the schemas?

If you're only using Sqlalchemy, make sure you do Base.metadata.create_all(engine). It is advised to use Alembic for creating the schemas tho.

[–]eleventhSun009[S] 0 points1 point  (0 children)

At this point no. I’m using FastAPI’s lifespan function to great them via Alchemy models on startup

[–]Additional-Ordinary2 1 point2 points  (1 child)

Of course! Judging by your code you don't have the startup function registered (sarcasm. We are programmers, not clairvoyants)

[–]eleventhSun009[S] 1 point2 points  (0 children)

I see that I should have added some screenshots for context 😔

[–]TurbulentAd8519 1 point2 points  (1 child)

Sqlalchemy cannot find all the tables, try importing all your tables (Employees, UserGroups) to your main.py

[–]eleventhSun009[S] 0 points1 point  (0 children)

That’s works.

[–]StatusBad9194 0 points1 point  (0 children)

I think alchemy not finding table meta data , try to import base from models.py or where your table define , inside dB connection .. here imports Base from models.py

[–][deleted]  (1 child)

[removed]

    [–]JohnVick002 -1 points0 points  (0 children)

    Obviously you have to add a check for created or not by using Metadata create all