knex/knex · error · Error
replace views is not supported by this dialect.
Error message
replace views is not supported by this dialect.
What it means
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.'
Source
Thrown at lib/schema/viewcompiler.js:44
this.sequence = [];
}
// Convert the tableCompiler toSQL
toSQL() {
this[this.method]();
return this.sequence;
}
// Column Compilation
// -------
create() {
this.createQuery(this.columns, this.selectQuery);
}
createOrReplace() {
throw new Error('replace views is not supported by this dialect.');
}
createMaterializedView() {
throw new Error('materialized views are not supported by this dialect.');
}
createQuery(columns, selectQuery, materialized, replace) {
const createStatement =
'create ' +
(materialized ? 'materialized ' : '') +
(replace ? 'or replace ' : '') +
'view ';
const columnList = columns
? ' (' +
columnize_(
columns,
this.viewBuilder,
this.client,View on GitHub (pinned to e25d54bcb7)
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.
Example fix
// before
await knex.schema.createViewOrReplace('v').as(q);
// after
await knex.schema.dropViewIfExists('v');
await knex.schema.createView('v').as(q); Defensive patterns
Strategy: validation
Validate before calling
const supportsReplace = new Set(['postgres','mysql','mysql2']).has(knex.client.dialect);
if (supportsReplace) await knex.schema.createViewOrReplace('v').as(q);
else { await knex.schema.dropViewIfExists('v'); await knex.schema.createView('v').as(q); } Type guard
const supportsCreateOrReplaceView = (knex) => ['postgres','mysql','mysql2'].includes(knex.client.dialect);
Try / catch
try { await knex.schema.createViewOrReplace('v').as(q); }
catch (e) {
if (/replace views is not supported/.test(e.message)) {
await knex.schema.dropViewIfExists('v');
await knex.schema.createView('v').as(q);
} else throw e;
} Prevention
- Prefer drop+create for portable view migrations
- Check dialect support for CREATE OR REPLACE VIEW
- Test view migrations across engines
When it happens
Trigger: 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.
Common situations: SQLite has no CREATE OR REPLACE VIEW; using SQLite for a migration written for Postgres/MySQL; CI dialect mismatch.
Related errors
- materialized views are not supported by this dialect.
- rename view is not supported by this dialect (instead drop t
- check option definition is not supported by this dialect.
- materialized views are not supported by this dialect.
- rename view is not supported by this dialect (instead drop,
AI-assisted analysis of knex/knex@e25d54bcb7 (2026-08-03).
Data as JSON: /data/errors/5e241e2a4a94f98e.json.
Report an issue: GitHub.