strapi / strapi

🚀 Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable, and developer-first.
https://strapi.io
Other
63.15k stars 7.96k forks source link

mysql error on content-type change: ER_FK_DUP_NAME: Duplicate FOREIGN KEY constraint name #20283

Open jarnix opened 4 months ago

jarnix commented 4 months ago

Bug report

Required System information

Describe the bug

 Error: ER_FK_DUP_NAME: Duplicate FOREIGN KEY constraint name 'blog/admin_permissions_created_by_id_fk'                │
│       at Sequence._packetToError (/home/julien/web/blog3/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)   │
│       at Query.ErrorPacket (/home/julien/web/blog3/node_modules/mysql/lib/protocol/sequences/Query.js:79:18)            │
│       at Protocol._parsePacket (/home/julien/web/blog3/node_modules/mysql/lib/protocol/Protocol.js:291:23)              │
│       at Parser._parsePacket (/home/julien/web/blog3/node_modules/mysql/lib/protocol/Parser.js:433:10)                  │
│       at Parser.write (/home/julien/web/blog3/node_modules/mysql/lib/protocol/Parser.js:43:10)                          │
│       at Protocol.write (/home/julien/web/blog3/node_modules/mysql/lib/protocol/Protocol.js:38:16)                      │
│       at Socket.<anonymous> (/home/julien/web/blog3/node_modules/mysql/lib/Connection.js:88:28)                         │
│       at Socket.<anonymous> (/home/julien/web/blog3/node_modules/mysql/lib/Connection.js:526:10)                        │
│       at Socket.emit (node:events:519:28)                                                                               │
│       at Socket.emit (node:domain:488:12)                                                                               │
│       --------------------                                                                                              │
│       at Protocol._enqueue (/home/julien/web/blog3/node_modules/mysql/lib/protocol/Protocol.js:144:48)                  │
│       at Connection.query (/home/julien/web/blog3/node_modules/mysql/lib/Connection.js:198:25)                          │
│       at /home/julien/web/blog3/node_modules/knex/lib/dialects/mysql/index.js:132:18                                    │
│       at new Promise (<anonymous>)                                                                                      │
│       at Client_MySQL._query (/home/julien/web/blog3/node_modules/knex/lib/dialects/mysql/index.js:126:12)              │
│       at executeQuery (/home/julien/web/blog3/node_modules/knex/lib/execution/internal/query-executioner.js:37:17)      │
│       at Client_MySQL.query (/home/julien/web/blog3/node_modules/knex/lib/client.js:154:12)                             │
│       at /home/julien/web/blog3/node_modules/knex/lib/execution/transaction.js:371:24                                   │
│       at new Promise (<anonymous>)                                                                                      │
│       at trxClient.query (/home/julien/web/blog3/node_modules/knex/lib/execution/transaction.js:366:12)                 │
│

There is no way of going further. I have to delete every table and restart but I will lose every content of course.

Steps to reproduce the behavior

First launch, after creating the first user, going to the content-type builder, I added one field, and then clicked on Save. Strapi restarts with this error:

Expected behavior

The server should restart properly and not try to create duplicated foreign keys.

Additional context

This happens with mysql, not with a file db, there is no fk in the file db...

janaikerana96 commented 3 months ago

This error occurs because you are using a database user that does not have sufficient permissions to make changes to the database. Revert your code, and then try to connect with a user that has root privileges in the application.