Skip to content

Migrations do not detect a change on the database dialect #5235

Open

Description

@marcelomendoncasoares

When a project is created using one database dialect (SQLite for example) and later changed to other (Postgres), the next call to a create-migration will detect no changes unless the models have changed. This is wrong in two ways:

  • If the models have changed, no existing database will ever be able to migrate from the last version because its SQL targets a different dialect.
  • If the models have not changed, we need a new SQL that targets the current database dialect to be able to start the server, or it will face runtime errors.

The correct solution is to detect that the dialect have changed and ask for --force to completely wipe the existing migrations and create a new one.

Activity

  1. added
    bug
    area: migrations
    on May 27, 2026
  2. moved this from Inbox 📫 to Contributor In Progress 👩‍💻 in Serverpod Frameworkson May 27, 2026
  3. moved this from Contributor In Progress 👩‍💻 to Planned 🔭 in Serverpod Frameworkson May 27, 2026
  4. moved this from Planned 🔭 to Next Up 🎯 in Serverpod Frameworkson Jun 12, 2026
  5. moved this from Next Up 🎯 to Planned 🔭 in Serverpod Frameworkson Jun 19, 2026
  6. nicowalter256 commented on Jun 19, 2026

    @nicowalter256
    Contributor

    is this fixed?

  7. marcelomendoncasoares commented on Jun 20, 2026

    @marcelomendoncasoares
    CollaboratorAuthor

    @nicowalter256 Not yet. The design that needs thinking for this issue is the best way to track the previous dialect version. A possible alternative is a formatted comment at the top of the definition.sql and migration.sql. Using the *.json files is not ideal because they are dialect-agnostic - and loaded separately from the *.sql files. Adding another file is also not a good idea because each migration folder already has many files. Feel free to explore/propose other options. I'll only suggest we agree on the direction here before you jump to implement.

  8. nicowalter256 commented on Jun 20, 2026

    @nicowalter256
    Contributor

    wanna contribute to some other issue. any suggestions

  9. abdulawalarif commented on Jul 3, 2026

    @abdulawalarif
    Contributor

    Hi, @marcelomendoncasoares
    I've reviewed the issue. The migrations rely only on model snapshots, which are dialect-agnostic, so when we switch databases, it silently fails.
    We can add a small, machine-readable header inside each migration SQL file that records the dialect.
    Then, before creating or applying migrations, we check that header against the current config.
    If they are different, the system stops and asks for a force flag before resetting the migrations. This way, we prevent accidental mismatches.
    Let me know if you think this is okay.

  10. abdulawalarif commented on Jul 5, 2026

    @abdulawalarif
    Contributor

    Hi, @marcelomendoncasoares @SandPod @dkbast , I've reproduced this issue and would like to start working on a fix.. Can anyone please assign this to me?

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

    area: migrationsbug

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions