{"record":{"id":"254403c35a68a40e","repo":"OrchardCMS/OrchardCore","slug":"the-field-name-field-in-model-name-part-was-defined-without","errorCode":null,"errorMessage":"The '{field.Name}' field in '{model.Name}' part was defined without a specified type. Please review the migration and explicitly specify the field type.","messagePattern":"The '(.+?)' field in '(.+?)' part was defined without a specified type\\. Please review the migration and explicitly specify the field type\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.ContentManagement/ContentDefinitionManager.cs","lineNumber":319,"sourceCode":"            .Where(partFieldDefinitionRecord => !model.Fields\n                .Any(partField => partField.Name.EqualsOrdinalIgnoreCase(partFieldDefinitionRecord.Name)))\n            .ToArray();\n\n        foreach (var remove in toRemove)\n        {\n            record.ContentPartFieldDefinitionRecords.Remove(remove);\n        }\n\n        foreach (var field in model.Fields)\n        {\n            var partFieldRecord = record.ContentPartFieldDefinitionRecords\n                .FirstOrDefault(partField => partField.Name.EqualsOrdinalIgnoreCase(field.Name));\n\n            if (partFieldRecord is null)\n            {\n                if (field.FieldDefinition is null)\n                {\n                    throw new InvalidOperationException(\n                        $\"The '{field.Name}' field in '{model.Name}' part was defined without a specified type.\" +\n                        \" Please review the migration and explicitly specify the field type.\");\n                }\n\n                partFieldRecord = new ContentPartFieldDefinitionRecord\n                {\n                    FieldName = field.FieldDefinition.Name,\n                    Name = field.Name,\n                };\n\n                record.ContentPartFieldDefinitionRecords.Add(partFieldRecord);\n            }\n\n            Apply(field, partFieldRecord);\n        }\n    }\n\n    private static void Apply(ContentPartFieldDefinition model, ContentPartFieldDefinitionRecord record)","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.ContentManagement/ContentDefinitionManager.cs#L301-L337","documentation":"During content definition migrations, adding a field to a part requires an explicit FieldDefinition (the field type). When a migration adds a field whose type was not specified, ContentDefinitionManager.Apply throws to prevent persisting a field record with no type, which would break rendering and querying later.","triggerScenarios":"Calling BuildPart/WithField in a migration step without chaining .WithFieldType<T> or providing the field definition, then Apply()-ing the migration.","commonSituations":"Copy-pasted migration code missing the field type call; refactored migrations after upgrading where field-type APIs changed; dynamically constructed field definitions that left FieldDefinition null.","solutions":["Add .WithFieldType<TField>() (e.g., TextField, BooleanField) to the field definition in the migration","Review the migration code and specify the field type explicitly for every field","Fix data that produced a null FieldDefinition if fields are built dynamically"],"exampleFix":"// before\n_builder.WithPart(\"MyPart\", p => p.WithField(\"Count\", f => f.OfType(null)));\n// after\n_builder.WithPart(\"MyPart\", p => p.WithField(\"Count\", f => f.OfType(\"NumberField\")));","handlingStrategy":"validation","validationCode":"foreach (var f in part.Fields) { if (f.FieldDefinition is null) throw new InvalidOperationException($\"Field '{f.Name}' needs WithFieldType in the migration.\"); }","typeGuard":"bool hasType = migrationField.FieldDefinition is not null;","tryCatchPattern":"try { await _contentDefinitionManager.ApplyMigrationsAsync(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"without a specified type\")) { /* fix migration code */ }","preventionTips":["Always chain .WithFieldType/OfType on every migration field","Test migrations on a fresh site","Review copy-pasted migration snippets for missing type calls"],"tags":["migration","content-definition","fields"],"backgroundTag":"missing-required-argument","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}