You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I was using the alembic migration functionality and noticed that Reflex generates quite some alembic configuration but does not use it. For instance, the generated alembic.ini file has sqlalchemy.url set to an example/dummy value, or that the alembic/env.py script is not used at all when generating/running migrations.
As an end-user, this is somewhat misleading, especially when trying to debug something database related. If the reflex CLI is interacting directly with the Alembic API, the unused generated configuration should ideally not be there.
To Reproduce
Steps to reproduce the behavior:
Code/Link to Repo:
Expected behavior
Two possibilities:
when running reflex db init, we could remove the sqlalchemy.url entry from alembic.ini, and consider removing the alembic/env.py file completely
alternatively, we could have the reflex CLI call out alembic commands instead of interacting directly with the alembic API. This would have the additional advantage of being able to rollback migrations to a previous state, which does not seem to be possible now.
Screenshots
If applicable, add screenshots to help explain your problem.
Specifics (please complete the following information):
Python Version: 3.11
Reflex Version: 0.2.2
OS:
Browser (Optional):
Additional context
Add any other context about the problem here.
I'm reading this almost year later. (reflex 0.4.x) and this is still the problem.
For me, reflex db makemigrations and reflex db migrate seem to have no effect
I see sqlite file being created with alembic_version table in it, but my default user table isn't created.
Also reflex db command provide no output error. No success, no error. Nothing :(
If there are logs, where are they created ? I don't see anything on console
For me, reflex db makemigrations and reflex db migrate seem to have no effect
Ensure that your main app module is importing your Model objects, otherwise Reflex will not know they are there.
This was exactly the problem (and solution) - although it is not clear from the documentation.
One other point. As mentioned by @siddhantgoel , now that migration seem to be automatically run (At least for the first time) - message (from alembic I assume) to check alembic.ini seems confusing/redundant. sqlalchemy.url is still the placeholder string, but does not seem to be a problem.
For me, reflex db makemigrations and reflex db migrate seem to have no effect
Ensure that your main app module is importing your Model objects, otherwise Reflex will not know they are there.
Yes, importing all the models in the main app module ensures that reflex db makemigrations detects them correctly for standard models.
However, in my prototype, there are legacy or external tables in the database that don’t have corresponding Reflex models, and creating models for them isn’t necessary, since the app operates on a large, pre-existing database. Currently, Reflex includes all detected tables when generating migrations, and there doesn’t seem to be a built-in way to filter or exclude specific tables.
Beyond using Alembic directly, is there a recommended approach within Reflex to handle selective table inclusion/exclusion? Are there any plans to support this natively in future releases?
Activity
mandarvaze commentedon Apr 11, 2024
I'm reading this almost year later. (reflex 0.4.x) and this is still the problem.
For me,
reflex db makemigrationsandreflex db migrateseem to have no effectI see sqlite file being created with
alembic_versiontable in it, but my defaultusertable isn't created.Also
reflex dbcommand provide no output error. No success, no error. Nothing :(If there are logs, where are they created ? I don't see anything on console
masenf commentedon Apr 11, 2024
Ensure that your main app module is importing your Model objects, otherwise Reflex will not know they are there.
mandarvaze commentedon Apr 12, 2024
This was exactly the problem (and solution) - although it is not clear from the documentation.
One other point. As mentioned by @siddhantgoel , now that migration seem to be automatically run (At least for the first time) - message (from alembic I assume) to check
alembic.iniseems confusing/redundant.sqlalchemy.urlis still the placeholder string, but does not seem to be a problem.SerDieFer commentedon Sep 1, 2025
Yes, importing all the models in the main app module ensures that
reflex db makemigrationsdetects them correctly for standard models.However, in my prototype, there are legacy or external tables in the database that don’t have corresponding Reflex models, and creating models for them isn’t necessary, since the app operates on a large, pre-existing database. Currently, Reflex includes all detected tables when generating migrations, and there doesn’t seem to be a built-in way to filter or exclude specific tables.
Beyond using Alembic directly, is there a recommended approach within Reflex to handle selective table inclusion/exclusion? Are there any plans to support this natively in future releases?