vitessio/vitess · error
mismatched entity type
Error message
mismatched entity type
What it means
ErrEntityTypeMismatch is a sentinel error in the schemadiff package indicating that two entities (table vs view, etc.) being compared do not share the same entity type. Diffing or applying a diff only makes sense between entities of the same kind, so functions like Diff/Apply and NewCreateTable/NewCreateViewEntityFromSQL return this when the kinds differ.
Source
Thrown at go/vt/schemadiff/errors.go:29
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package schemadiff
import (
"errors"
"fmt"
"strings"
"vitess.io/vitess/go/sqlescape"
"vitess.io/vitess/go/vt/sqlparser"
)
var (
ErrEntityTypeMismatch = errors.New("mismatched entity type")
ErrStrictIndexOrderingUnsupported = errors.New("strict index ordering is unsupported")
ErrUnexpectedDiffAction = errors.New("unexpected diff action")
ErrUnexpectedTableSpec = errors.New("unexpected table spec")
ErrExpectedCreateTable = errors.New("expected a CREATE TABLE statement")
ErrExpectedCreateView = errors.New("expected a CREATE VIEW statement")
)
type ImpossibleApplyDiffOrderError struct {
UnorderedDiffs []EntityDiff
ConflictingDiffs []EntityDiff
}
func (e *ImpossibleApplyDiffOrderError) Error() string {
var b strings.Builder
conflictingStatements := e.ConflictingStatements()
fmt.Fprintf(&b, "no valid applicable order for diffs. %d diffs found conflicting:", len(conflictingStatements))
for _, s := range conflictingStatements {
b.WriteString("\n")View on GitHub (pinned to 01a25a7d17)
Solutions
- Rename one of the entities so the table and view do not collide
- Drop the existing entity and re-create it as the intended type before diffing
- Ensure the correct entity constructor (CreateTable vs CreateView) is used for the statement
Example fix
// before
createTable := "CREATE TABLE t1 (id INT)"
entity1, _ := schemadiff.NewCreateTableEntityFromSQL(createTable)
viewEntity, _ := schemadiff.NewCreateViewEntityFromSQL("CREATE VIEW t1 AS SELECT 1")
entity1.Diff(viewEntity) // mismatched entity type
// after
viewEntity2, _ := schemadiff.NewCreateViewEntityFromSQL("CREATE VIEW t1 AS SELECT 1")
viewEntity.Diff(viewEntity2) // OK: same entity type Defensive patterns
Strategy: validation
Validate before calling
func sameEntityType(a, b schemadiff.Entity) bool { return a.Type() == b.Type() }
// call entity.Diff(other) only when sameEntityType(entity, other) Type guard
func isTableEntity(e schemadiff.Entity) bool {
_, ok := e.(*schemadiff.CreateTableEntity)
return ok
} Prevention
- Always build entities with the constructor matching the statement kind
- Group tables and views into separate schema diff inputs
- Keep table and view names disjoint in your keyspace
When it happens
Trigger: Calling Entity.Diff() or EntityDiff.Apply() where one side is a table entity and the other is a view entity for the same name; constructing entities from SQL where the parsed statement type does not match the expected entity type.
Common situations: A keyspace schema where a table was replaced by a view (or vice versa) with the same name; scripts that mix up table and view definitions when generating schema input files.
Related errors
- strict index ordering is unsupported
- unexpected diff action
- unexpected table spec
- expected a CREATE TABLE statement
- expected a CREATE VIEW statement
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/2663fa69c2c97808.
Report an issue: GitHub.