typeorm,mysql ER_PARSE_ERROR 迁移期间
typeorm, mysql ER_PARSE_ERROR during migration
我想将模拟数据添加到我的项目中。所以我尝试使用 typeorm 进行迁移。
npx typeorm migration:create -n FakePosts
创建迁移后,我使用typeorm中的queryRunner插入数据。
1642424231242235-FakePosts.ts
import {MigrationInterface, QueryRunner} from "typeorm";
export class FakePosts1642424231242235 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
queryRunner.query(`
insert into post (userId, type, title, texts) values (1, 3, 'Tulpan', 'Nullam sit amet
turpis elementum ligula vehicula consequat. Morbi a ipsum. Integer a nibh.
In quis justo. Maecenas rhoncus aliquam lacus. Morbi quis tortor id nulla ultrices
aliquet.');
insert into post (userId, type, title, texts) values (1, 3, 'Look, Up in the Sky! The
Amazing Story of Superman', 'Proin leo odio, porttitor id, consequat in, consequat ut, nulla.
Sed accumsan felis. Ut at dolor quis odio consequat varius.');
`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
}
}
在index.ts
里面
await conn.runMigrations();
但是我遇到了这个错误。
error: Error: ER_PARSE_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 'insert into post (userId, type, title, texts) values (1, 3, 'Look, Up in the ...' at line 2
我认为我的 SQL 语法没有任何错误,但 mysql 对我很生气。
有什么问题?
您有多个查询,需要添加
,multipleStatements: true
到连接字符串
我想将模拟数据添加到我的项目中。所以我尝试使用 typeorm 进行迁移。
npx typeorm migration:create -n FakePosts
创建迁移后,我使用typeorm中的queryRunner插入数据。
1642424231242235-FakePosts.ts
import {MigrationInterface, QueryRunner} from "typeorm";
export class FakePosts1642424231242235 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
queryRunner.query(`
insert into post (userId, type, title, texts) values (1, 3, 'Tulpan', 'Nullam sit amet
turpis elementum ligula vehicula consequat. Morbi a ipsum. Integer a nibh.
In quis justo. Maecenas rhoncus aliquam lacus. Morbi quis tortor id nulla ultrices
aliquet.');
insert into post (userId, type, title, texts) values (1, 3, 'Look, Up in the Sky! The
Amazing Story of Superman', 'Proin leo odio, porttitor id, consequat in, consequat ut, nulla.
Sed accumsan felis. Ut at dolor quis odio consequat varius.');
`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
}
}
在index.ts
里面await conn.runMigrations();
但是我遇到了这个错误。
error: Error: ER_PARSE_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 'insert into post (userId, type, title, texts) values (1, 3, 'Look, Up in the ...' at line 2
我认为我的 SQL 语法没有任何错误,但 mysql 对我很生气。
有什么问题?
您有多个查询,需要添加
,multipleStatements: true
到连接字符串