{"id":"5e241e2a4a94f98e","repo":"knex/knex","slug":"replace-views-is-not-supported-by-this-dialect","errorCode":null,"errorMessage":"replace views is not supported by this dialect.","messagePattern":"replace views is not supported by this dialect\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/schema/viewcompiler.js","lineNumber":44,"sourceCode":"\n    this.sequence = [];\n  }\n\n  // Convert the tableCompiler toSQL\n  toSQL() {\n    this[this.method]();\n    return this.sequence;\n  }\n\n  // Column Compilation\n  // -------\n\n  create() {\n    this.createQuery(this.columns, this.selectQuery);\n  }\n\n  createOrReplace() {\n    throw new Error('replace views is not supported by this dialect.');\n  }\n\n  createMaterializedView() {\n    throw new Error('materialized views are not supported by this dialect.');\n  }\n\n  createQuery(columns, selectQuery, materialized, replace) {\n    const createStatement =\n      'create ' +\n      (materialized ? 'materialized ' : '') +\n      (replace ? 'or replace ' : '') +\n      'view ';\n    const columnList = columns\n      ? ' (' +\n        columnize_(\n          columns,\n          this.viewBuilder,\n          this.client,","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/knex/knex/blob/e25d54bcb707714a17f5a5744eba5c4246bb4d1d/lib/schema/viewcompiler.js#L26-L62","documentation":"ViewCompiler.createOrReplace is the base throwing stub (lib/schema/viewcompiler.js:43) for CREATE OR REPLACE VIEW. Dialects that support replace semantics override it (createQuery with replace=true); dialects without native support let the base throw 'replace views is not supported by this dialect.'","triggerScenarios":"Calling knex.schema.createViewOrReplace(...) (or createView with replace option) against a dialect whose ViewCompiler does not override createOrReplace. The toSQL dispatcher (line 32) calls this[method] which hits the stub.","commonSituations":"SQLite has no CREATE OR REPLACE VIEW; using SQLite for a migration written for Postgres/MySQL; CI dialect mismatch.","solutions":["Use a dialect that supports CREATE OR REPLACE VIEW (postgres/mysql).","Emulate by dropping then creating the view (the error message itself suggests this).","Gate the call behind a dialect check.","Switch to plain createView and manage the drop manually."],"exampleFix":"// before\nawait knex.schema.createViewOrReplace('v').as(q);\n// after\nawait knex.schema.dropViewIfExists('v');\nawait knex.schema.createView('v').as(q);","handlingStrategy":"validation","validationCode":"const supportsReplace = new Set(['postgres','mysql','mysql2']).has(knex.client.dialect);\nif (supportsReplace) await knex.schema.createViewOrReplace('v').as(q);\nelse { await knex.schema.dropViewIfExists('v'); await knex.schema.createView('v').as(q); }","typeGuard":"const supportsCreateOrReplaceView = (knex) =>\n  ['postgres','mysql','mysql2'].includes(knex.client.dialect);","tryCatchPattern":"try { await knex.schema.createViewOrReplace('v').as(q); }\ncatch (e) {\n  if (/replace views is not supported/.test(e.message)) {\n    await knex.schema.dropViewIfExists('v');\n    await knex.schema.createView('v').as(q);\n  } else throw e;\n}","preventionTips":["Prefer drop+create for portable view migrations","Check dialect support for CREATE OR REPLACE VIEW","Test view migrations across engines"],"tags":["schema","views","dialect","create-or-replace"],"analyzedSha":"e25d54bcb707714a17f5a5744eba5c4246bb4d1d","analyzedAt":"2026-08-03T18:35:32.148Z","schemaVersion":2}