pymysql.err.OperationalError: (4091, "Unknown SEQUENCE: 'SOME SEQUENCE'")

Hello everyone,

I’ve recently started developing with the Frappe Framework and have been enjoying the process so far. However, I’ve encountered a recurring issue that I need help resolving.

**

pymysql.err.OperationalError: (4091, “Unknown SEQUENCE: ‘SOME SEQUENCE’”)

**

The error occurs when a DocType is initially configured with a Naming Rule other than “Auto Increment” (e.g., “Set by User,” “Expression,” etc.) and is later switched to “Auto Increment.” After making this change, an error appears. On one occasion, I managed to bypass the error by temporarily changing the Naming Rule to something else and then reverting it back to “Auto Increment.” However, this workaround is no longer effective.

Since my project is in the early stages of development with no customer data in production, I’m considering removing the app, cleaning up the database and tables, and reinstalling. While this solution works for now, I’m concerned about handling such errors in a live production environment where removing the app isn’t an option.

I’ve noticed multiple similar bug reports in the GitHub repository, but most of them seem to be closed without a resolution, which is worrying.

Is there a way to resolve this issue using a database script, a patch, or another migration strategy without removing the app? Or is there something I should do to prevent this error from happening in the first place?

Thank you in advance for your help!