Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

typeorm, mysql ER_PARSE_ERROR during migration

I wanted to add mock data to my project. So I tried to do migration with typeorm.

npx typeorm migration:create -n FakePosts

After creating migration, I used queryRunner in typeorm to insert data.

1642424231242235-FakePosts.ts

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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> {
    }
}

inside of index.ts

await conn.runMigrations();

But I got this Error.

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

I think that I don’t have any errors in my SQL syntax but mysql is mad at me.

What is the problem?

>Solution :

you have multiple qeries, so you need to add

,multipleStatements: true 

to the connection string

see manual

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading