Fresh Install, saving flows fails (executing succeeds)

With a fresh install of n8n, when I attempt to save a workflow I get:

ERROR RESPONSE

TypeError: Cannot read property 'toString' of undefined

at /usr/local/lib/node_modules/n8n/dist/src/Server.js:290:35

at processTicksAndRejections (internal/process/task_queues.js:93:5)

at async /usr/local/lib/node_modules/n8n/dist/src/ResponseHelper.js:76:26

I also receive this if I go to save a 2nd flow:

at addChunk (internal/streams/readable.js:309:12)

at readableAddChunk (internal/streams/readable.js:284:9)

at Socket.Readable.push (internal/streams/readable.js:223:10)

at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {

code: 'ER_DUP_ENTRY',

errno: 1062,

sqlState: '23000',

sqlMessage: "Duplicate entry '0' for key 'PRIMARY'",

query: 'INSERT INTO `workflow_entity`(`id`, `name`, `active`, `nodes`, `connections`, `createdAt`, `updatedAt`, `settings`, `staticData`) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, DEFAULT)',

parameters: [

'asdf',

0,

'[{"parameters":{},"name":"Start","type":"n8n-nodes-base.start","typeVersion":1,"position":[250,300]}]',

'{}',

2021-05-19T06:05:44.301Z,

2021-05-19T06:05:44.301Z,

'{}'

]

}

I have wiped my mysqldb and reinstalled. Same thing. I’m only able to save one flow (with a toString error). Afterwards, I’m unable to save anymore due to this PRIMARY violation.
phpMyAdmin shows 1 record in workflow_entity,

Tried on both n8n Version: 0.112.0 and 0.120.0

Hi @DanSputnikk

Welcome to our forums!

I had a quick look at the error you are having and this seems to be happening because MYSQL is not returning the inserted id.

Can you share the MySQL version you are using? I will try to test it using the same version as you and see if I can replicate the problem.

1 Like

image

Screenshot from phpMyAdmin connected to the same source DB server.

Hello @DanSputnikk

Thanks for the update. I just tested using MariaDB in the same version you’re using but in Docker.

I ran this using the latest version (0.121.0).

I did not perform any change to the docker image, simply ran MariaDB with default settings from the fresh docker image and I was able to correctly save 2 workflows.

Execute workflows a few times, tweaked a few n8n workflow settings (which causes n8n workflows to be saved) and created new ones, all working fine.

I guess it might have something to do with the way MariaDB was configure perhaps?

From phpMyAdmin can you check if the workflow_entity table was created with the correct auto increment setting for the ID field? This is something n8n should do by default but it seems to be causing the error on your instance.

Also can you check the migrations table contains rows? Mine looks like this:

Screenshot from 2021-05-21 11-29-40

I will check these and get back to you. Thanks.

For the record, this is MariaDB Galera - which should just be MariaDB in a cluster.

I’m in K8, versus Docker… but you know. Same thing.

Good point you mentioned this.

Maybe it has a different behavior as it runs on clusters?

n8n relies on returning the auto increment ID (which works fine for single instance MariaDB) but cluster version might be slightly different in this behavior.

Unfortunately I am not an expert on this but this is a good starting point.

workflow_entity has AUTO_INCREMENT:

migrations table looks like yours: