{"record":{"id":"2663fa69c2c97808","repo":"vitessio/vitess","slug":"mismatched-entity-type","errorCode":null,"errorMessage":"mismatched entity type","messagePattern":"mismatched entity type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/schemadiff/errors.go","lineNumber":29,"sourceCode":"distributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\npackage schemadiff\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"strings\"\n\n\t\"vitess.io/vitess/go/sqlescape\"\n\t\"vitess.io/vitess/go/vt/sqlparser\"\n)\n\nvar (\n\tErrEntityTypeMismatch             = errors.New(\"mismatched entity type\")\n\tErrStrictIndexOrderingUnsupported = errors.New(\"strict index ordering is unsupported\")\n\tErrUnexpectedDiffAction           = errors.New(\"unexpected diff action\")\n\tErrUnexpectedTableSpec            = errors.New(\"unexpected table spec\")\n\tErrExpectedCreateTable            = errors.New(\"expected a CREATE TABLE statement\")\n\tErrExpectedCreateView             = errors.New(\"expected a CREATE VIEW statement\")\n)\n\ntype ImpossibleApplyDiffOrderError struct {\n\tUnorderedDiffs   []EntityDiff\n\tConflictingDiffs []EntityDiff\n}\n\nfunc (e *ImpossibleApplyDiffOrderError) Error() string {\n\tvar b strings.Builder\n\tconflictingStatements := e.ConflictingStatements()\n\tfmt.Fprintf(&b, \"no valid applicable order for diffs. %d diffs found conflicting:\", len(conflictingStatements))\n\tfor _, s := range conflictingStatements {\n\t\tb.WriteString(\"\\n\")","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/schemadiff/errors.go#L11-L47","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ncreateTable := \"CREATE TABLE t1 (id INT)\"\nentity1, _ := schemadiff.NewCreateTableEntityFromSQL(createTable)\nviewEntity, _ := schemadiff.NewCreateViewEntityFromSQL(\"CREATE VIEW t1 AS SELECT 1\")\nentity1.Diff(viewEntity) // mismatched entity type\n// after\nviewEntity2, _ := schemadiff.NewCreateViewEntityFromSQL(\"CREATE VIEW t1 AS SELECT 1\")\nviewEntity.Diff(viewEntity2) // OK: same entity type","handlingStrategy":"validation","validationCode":"func sameEntityType(a, b schemadiff.Entity) bool { return a.Type() == b.Type() }\n// call entity.Diff(other) only when sameEntityType(entity, other)","typeGuard":"func isTableEntity(e schemadiff.Entity) bool {\n\t_, ok := e.(*schemadiff.CreateTableEntity)\n\treturn ok\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["schemadiff","schema-migration","type-mismatch"],"backgroundTag":"entity-type-mismatch","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}