Skip to content

DBForge can rewrite table column names when they contain exp if db prefix is not default #5299

Open

Description

@robinsowell

Ran into this with a cartthrob table that has columns named exp_month, exp_day - don't ask me why, but those are the COLUMN names.

User upgrading from CT 8.1 to CT 9B, here is the error I am getting:

SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'ee_month':
ALTER TABLE ee_cartthrob_vault ADD ee_month varchar(100) NULL

Note- the column name should be exp_month. Note also, ee is what he's using for the table prefix instead of the default exp.

What's happening-

EE sets swap_pre = 'exp_' globally on boot
Core.php (line 116)

Every query then runs a global regex replacement from swap_pre to current dbprefix
DB_driver.php (line 182)
That replacement is not table-only; it will rewrite identifier tokens like exp_month to ee_month when prefix is ee_.

CT updater defines vault columns exp_month/exp_year and adds missing columns via DBForge. So with dbprefix = ee_, ADD exp_month becomes ADD ee_month, which causes the duplicate-column failure pattern.

recommended fix:

Scope swap_pre so it does not run during DBForge schema queries
In EE core, DBForge already prefixes table names itself ($this->db->dbprefix . $table), so swap_pre is unnecessary there and harmful.

The safest patch is to temporarily set ee()->db->swap_pre = '' around DBForge query execution (add_column, modify_column, etc.), then restore it.

Activity

  1. added
    Bug: Accepted
    on May 27, 2026
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

    Bug: Accepted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions