{"record":{"id":"ec5bbc15f7762bcc","repo":"HumanSignal/label-studio","slug":"database-error-during-project-creation-try-again","errorCode":null,"errorMessage":"Database error during project creation. Try again.","messagePattern":"Database error during project creation\\. Try again\\.","errorType":"exception","errorClass":"LabelStudioDatabaseException","httpStatus":null,"severity":"critical","filePath":"label_studio/projects/api.py","lineNumber":223,"sourceCode":"        if self.request.method == 'GET' and sparse_fields is not None:\n            fields_param = settings.REST_FLEX_FIELDS.get('FIELDS_PARAM', 'fields')\n            kwargs[fields_param] = sparse_fields\n        return super().get_serializer(*args, **kwargs)\n\n    def get_serializer_context(self):\n        context = super(ProjectListAPI, self).get_serializer_context()\n        context['created_by'] = self.request.user\n        return context\n\n    def perform_create(self, ser):\n        try:\n            ser.save(organization=self.request.user.active_organization)\n        except IntegrityError as e:\n            if str(e) == 'UNIQUE constraint failed: project.title, project.created_by_id':\n                raise ProjectExistException(\n                    'Project with the same name already exists: {}'.format(ser.validated_data.get('title', ''))\n                )\n            raise LabelStudioDatabaseException('Database error during project creation. Try again.')\n\n    def get(self, request, *args, **kwargs):\n        return super(ProjectListAPI, self).get(request, *args, **kwargs)\n\n    @api_webhook(WebhookAction.PROJECT_CREATED)\n    def post(self, request, *args, **kwargs):\n        return super(ProjectListAPI, self).post(request, *args, **kwargs)\n\n\n@method_decorator(\n    name='get',\n    decorator=extend_schema(\n        tags=['Projects'],\n        summary=\"List projects' counts\",\n        parameters=[\n            *serializer_to_openapi_params(GetFieldsSerializer),\n            *filterset_to_openapi_params(ProjectFilterSet),\n        ],","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/projects/api.py#L205-L241","documentation":"Generic fallback in ProjectListAPI.perform_create: when saving a new project raises an IntegrityError that is NOT the known duplicate-title constraint, it is converted to LabelStudioDatabaseException with this message. It signals an unexpected database-level failure during project creation.","triggerScenarios":"POST /api/projects where ser.save() raises IntegrityError for any reason other than 'UNIQUE constraint failed: project.title, project.created_by_id' (e.g. FK constraint violation, other unique constraint, data truncation raising as integrity error in some backends).","commonSituations":"DB migrations out of sync (missing columns/constraints differing from the code); PostgreSQL vs SQLite constraint message differences; corrupted data or FK mismatched organization/user; running an older DB schema against newer code.","solutions":["Check Django/DB logs for the underlying IntegrityError details","Run pending migrations (python label_studio/manage.py migrate)","Verify DB schema matches the installed Label Studio version","Retry the creation after fixing schema/data; escalate with the original traceback"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight: verify DB schema is current\n// python label_studio/manage.py migrate --check","typeGuard":null,"tryCatchPattern":"try:\n    project = await axios.post('/api/projects', payload);\ncatch (e) {\n  if (e.response?.status === 500 && /database/i.test(e.message)) {\n    // check server logs for IntegrityError, run migrations, retry once\n  } else throw e;\n}","preventionTips":["Keep DB migrations applied before deploying new versions","Use one supported DB backend per environment","Capture server-side logs when creation fails","Avoid hand-editing project rows in the DB"],"tags":["database","integrity-error","django","rest"],"backgroundTag":"database-integrity-error","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}