thisAKcode / fastapi_streetart_map

0 stars 0 forks source link

1 to many #23

Closed thisAKcode closed 1 year ago

thisAKcode commented 1 year ago

Hey, I am still stuck at 1-M modelling. I created a new models as per your suggestion> I tried to recreate the db (cut out mydb.db sqlite file into /backup) , then I expect that following will bring the new db with new , tables and schemas: app/main.py

@app.on_event("startup")
async def startup_populate_db():
    db = SessionLocal()
    item_count = db.query(model.Item).count()
    if item_count == 0:
        insert_items(DUMMY_DATA)

Then I get :

    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such column: item._data

Weird since I not only miss _data column, the entire db is not there...

thisAKcode commented 1 year ago

Hey, I am still stuck at 1-M modelling. I created a new models as per your suggestion> I tried to recreate the db (cut out mydb.db sqlite file into /backup) , then I expect that following will bring the new db with new , tables and schemas: app/main.py

@app.on_event("startup")
async def startup_populate_db():
    db = SessionLocal()
    item_count = db.query(model.Item).count()
    if item_count == 0:
        insert_items(DUMMY_DATA)

Then I get :

    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such column: item._data

Weird since I not only miss _data column, the entire db is not there...

I reviewed that myself is that because of my Schemas.py are not the sames as model.py? In this case you do not need to review in detail I'll just work on it further.

bbelderbos commented 1 year ago

OK let me know what fixed it ...

Now I remember you had to define pydantic and sqlalchemy models which causes some duplicated code, SQLModel solves this :)

thisAKcode commented 1 year ago

Well, it was silly mistake : I removed mydb.db from root but it existed also in /app/ wich application tried to insert into, of course error 'missing column blabla' was appropriate error then. I couldn't make pr tonight. Maybe tomorrow otherwise it can wait untill next week. Alex

Hämta Outlook for Androidhttps://aka.ms/AAb9ysg


From: Bob Belderbos @.> Sent: Wednesday, December 7, 2022 3:57:17 PM To: thisAKcode/fastapi_streetart_map @.> Cc: Alex_K @.>; Author @.> Subject: Re: [thisAKcode/fastapi_streetart_map] 1 to many (PR #23)

OK let me know what fixed it ...

Now I remember you had to define pydantic and sqlalchemy models which causes some duplicated code, SQLModel solves this :)

— Reply to this email directly, view it on GitHubhttps://github.com/thisAKcode/fastapi_streetart_map/pull/23#issuecomment-1341087881, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKOBMJXCNX55IA3O2S6P66DWMCQU3ANCNFSM6AAAAAASTTES6A. You are receiving this because you authored the thread.Message ID: @.***>

bbelderbos commented 1 year ago

oh sneaky so two databases and it accessed the wrong one?

thisAKcode commented 1 year ago

No both were with old data schema, goal was to remove db and create it from scratch, wich i thought was done. Sorry I was sick this week so I couldn't code so much but I have todos so I ll try to code it soon , hopefully during weekend

Hämta Outlook for Androidhttps://aka.ms/AAb9ysg


From: Bob Belderbos @.> Sent: Friday, December 9, 2022 1:08:12 PM To: thisAKcode/fastapi_streetart_map @.> Cc: Alex_K @.>; Author @.> Subject: Re: [thisAKcode/fastapi_streetart_map] 1 to many (PR #23)

oh sneaky so two databases and it accessed the wrong one?

— Reply to this email directly, view it on GitHubhttps://github.com/thisAKcode/fastapi_streetart_map/pull/23#issuecomment-1344229145, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKOBMJS6NUYT5IX6H6YMSGLWMMOKZANCNFSM6AAAAAASTTES6A. You are receiving this because you authored the thread.Message ID: @.***>

bbelderbos commented 1 year ago

Yeah common issue, when you have real data in production, you need to use alembic though. Feel better!