Setting up Alembic for a Kivy android app

40 views
Skip to first unread message

Charles Mareau (Loumi)

unread,
Feb 18, 2025, 10:55:55 AM2/18/25
to Kivy users support

I am currently trying to build a mobile app using Python, Kivy and SQLAlchemy. However, I am having difficulty implementing database migrations using Alembic.

Basically, the migrations work just fine on my computer but Alembic is not finding any migrations when called from my phone. I am using buildozer for the APK building.

My guess is that Alembic is not finding the migrations files from the versions folder when run on android, probably because of a path issue.

Additional notes on the app functioning on Android :

  • The database is created correctly when the app the launched for the first time

  • When the app is launched, Alembic starts to run but doesn't find any migrations to apply. Then the app exits without any error code.

  • If I replace manually the database with one already up-to-date, the app runs smootly.

  • If I replace the database with one initialized but not up-to-date (containing the initial migration but not the updates). I get this error using adb logcat 

02-17 21:27:48.451 17547 21720 I python : Migration failed: Can't locate revision identified by '2c282135e834'
02-17 21:27:48.933 17547 21720 I python : Python for android ended.

For reference I have added all the necessary files. The app won't be able to work like this but you will at least have all the necessary code.

So far, I have tried many things to reset the way Alembic is looking for migrations but nothing works (and I have a hard time remembering everything I tried...)

Also, with the current code, this is the adb logcat i get when I launch the app for the first time (I removed everything before that is just about the normal kivy app setup) :

02-17 21:19:43.422 12846 17556 I python : [INFO ] [Window ] auto add sdl2 input provider
02-17 21:19:43.423 12846 17556 I python : [INFO ] [Window ] virtual keyboard not allowed, single mode, not docked 
02-17 21:19:43.672 12846 17556 I python : [INFO ] [Clipboard ] Provider: android 
02-17 21:19:43.912 12846 17556 I python : Final DB path: /data/user/0/com.cmareau.astat/files/astat.db 
02-17 21:19:43.912 12846 17556 I python : Path exists: False 
02-17 21:19:43.913 12846 17556 I python : Final DB path: /data/user/0/com.cmareau.astat/files/astat.db 
02-17 21:19:43.913 12846 17556 I python : Path exists: False 
02-17 21:19:43.914 12846 17556 I python : database url : sqlite:////data/user/0/com.cmareau.astat/files/astat.db 
02-17 21:19:43.914 12846 17556 I python : migration path: /data/data/com.cmareau.astat/files/app/migrations 
02-17 21:19:43.914 12846 17556 I python : Migration path content: ['2c282135e834_initial_migration.pyc', '3b4994652668_populate_grade_table.pyc', '__pycache__', 'db33e18bf97f_adding_of_todolist_sector_and_climbtodo_.pyc'
02-17 21:19:43.920 12846 17556 I python : Final DB path: /data/user/0/com.cmareau.astat/files/astat.db 
02-17 21:19:43.920 12846 17556 I python : Path exists: True 
02-17 21:19:43.920 12846 17556 I python : Android DB Path: /data/user/0/com.cmareau.astat/files/astat.db 
02-17 21:19:43.920 12846 17556 I python : File exists: True 
02-17 21:19:43.920 12846 17556 I python : Migration files: ['README', '__pycache__', 'env.pyc', 'script.py.mako', 'versions'
02-17 21:19:43.936 12846 17556 I python : Database migrations applied successfully. 
02-17 21:19:44.232 12846 17556 I python : Python for android ended.

I know that my question is not a direct Kivy issue but I hope that someone here will have come accross the same type of issue.

Thanks for your help.
astat.py
alembic.ini
env.py
database.py

Imraan Muctar

unread,
Feb 18, 2025, 11:08:48 AM2/18/25
to kivy-...@googlegroups.com
I think it could be better if you use supabase for your database 

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/kivy-users/1396df9f-8387-4a08-a25f-4718f60eeec3n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages