Skip to content

Remove misleading alembic configuration #1396

Closed

Description

@siddhantgoel

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:

  1. when running reflex db init, we could remove the sqlalchemy.url entry from alembic.ini, and consider removing the alembic/env.py file completely
  2. 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.

Activity

  1. added
    enhancement
    on Jul 24, 2023
  2. mandarvaze commented on Apr 11, 2024

    @mandarvaze

    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

  3. masenf commented on Apr 11, 2024

    @masenf
    Collaborator

    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.

  4. mandarvaze commented on Apr 12, 2024

    @mandarvaze

    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.

  5. SerDieFer commented on Sep 1, 2025

    @SerDieFer

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions