Skip to content

Commit 82f2b75

Browse files
Maczugapleerock
andauthored
fix: MariaDB VIRTUAL + [NOT NULL|NULL] error (#7022)
* Fix MariaDB VIRTUAL [NOT NULL|NULL] error Fixes #2691 query failed: ALTER TABLE `customer` CHANGE `fullName` `fullName` varchar(255) AS (CONCAT(`firstName`, ' ', `lastName`)) VIRTUAL NULL error: Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1 * slightly change code style to improve readability Co-authored-by: Umed Khudoiberdiev <[email protected]>
1 parent cdace6e commit 82f2b75

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/driver/mysql/MysqlQueryRunner.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,10 +1857,17 @@ export class MysqlQueryRunner extends BaseQueryRunner implements QueryRunner {
18571857
c += ` CHARACTER SET "${column.charset}"`;
18581858
if (column.collation)
18591859
c += ` COLLATE "${column.collation}"`;
1860-
if (!column.isNullable)
1861-
c += " NOT NULL";
1862-
if (column.isNullable)
1863-
c += " NULL";
1860+
1861+
const isMariaDb = this.driver.options.type === "mariadb";
1862+
if (isMariaDb && column.asExpression && (column.generatedType || "VIRTUAL") === "VIRTUAL") {
1863+
// do nothing - MariaDB does not support NULL/NOT NULL expressions for VIRTUAL columns
1864+
} else {
1865+
if (!column.isNullable)
1866+
c += " NOT NULL";
1867+
if (column.isNullable)
1868+
c += " NULL";
1869+
}
1870+
18641871
if (column.isPrimary && !skipPrimary)
18651872
c += " PRIMARY KEY";
18661873
if (column.isGenerated && column.generationStrategy === "increment") // don't use skipPrimary here since updates can update already exist primary without auto inc.

0 commit comments

Comments
 (0)