craftcms / craftcms/cms

Integrity constraint violation

Open
#7,652 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

Description

Bit stuck here. After taking a production db dump and importing it locally Im getting the following integrity constraint violation error when trying to create a new entry via the CP (/admin/entires/section/new). This error seems to disappear after refreshing the page a few times (the amount seems to change from dump to dump) but on each refresh the listed elementId appears to increment.

image

Another colleague has tried and is experiencing the same issue in their environment. We stumbled into an older issue but when checking the AUTO_INCREMENT values on the db dumps they seem to be correct:

SELECT id FROM elements
ORDER BY id DESC
LIMIT 1

image

SHOW CREATE TABLE elements

image

SELECT id FROM elements_sites
ORDER BY id DESC
LIMIT 1

image

SHOW CREATE TABLE elements_sites

image

Hoping this is something familiar or something I can receive some assistance/direction with.

Additional info
  • Craft version: Craft Pro 3.5.17.1
  • PHP version: 7.4.15
  • Database driver & version: MySQL 5.7.33

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the integrity constraint violation when creating a new entry in the CP after importing a production MySQL dump, and inspect the reported elementId as it changes across refreshes. Compare the elements and elements_sites IDs and AUTO_INCREMENT definitions shown in the issue; done means identifying the cause and preventing the failed entry creation.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.