Repository: directus/directus
File: api/src/services/collections.ts (TypeScript)

Code before:
						throw new InvalidPayloadError({ reason: `"fields" must be an array` });
					}

					/**
					 * Directus heavily relies on the primary key of a collection, so we have to make sure that
					 * every collection that is created has a primary key. If no primary key field is created
					 * while making the collection, we default to an auto incremented id named `id`
					 */

					const injectedPrimaryKeyField: RawField = {
						field: 'id',
						type: 'integer',
						meta: {
							hidden: true,
							interface: 'numeric',
							readonly: true,
						},
						schema: {
							is_primary_key: true,
							has_auto_increment: true,
						},
					};

					if (!payload.fields || payload.fields.length === 0) {
						payload.fields = [injectedPrimaryKeyField];
					} else if (payload.fields.some((f) => f.schema?.is_primary_key === true) === false) {
						payload.fields = [injectedPrimaryKeyField, ...payload.fields];
					}

					// Ensure that every field meta has the field/collection fields filled correctly
					payload.fields = payload.fields.map((field) => {
						if (field.meta) {
							field.meta = {
								...field.meta,
								field: field.field,
								collection: payload.collection!,
							};
						}

						// Add flag for specific database type overrides
						const flagToAdd = this.helpers.date.fieldFlagForField(field.type);

						if (flagToAdd) {
							addFieldFlag(field, flagToAdd);
						}

						return field;
					});

					const fieldsService = new FieldsService({ knex: trx, schema: this.schema });


Review comment (suggestion):
```suggestion
					} else if (!payload.fields.some((f) => f.schema?.is_primary_key === true)) {
```

Code after:
						throw new InvalidPayloadError({ reason: `"fields" must be an array` });
					}

					/**
					 * Directus heavily relies on the primary key of a collection, so we have to make sure that
					 * every collection that is created has a primary key. If no primary key field is created
					 * while making the collection, we default to an auto incremented id named `id`
					 */

					const injectedPrimaryKeyField: RawField = {
						field: 'id',
						type: 'integer',
						meta: {
							hidden: true,
							interface: 'numeric',
							readonly: true,
						},
						schema: {
							is_primary_key: true,
							has_auto_increment: true,
						},
					};

					if (!payload.fields || payload.fields.length === 0) {
						payload.fields = [injectedPrimaryKeyField];
					} else if (!payload.fields.some((f) => f.schema?.is_primary_key === true)) {
						payload.fields = [injectedPrimaryKeyField, ...payload.fields];
					}

					// Ensure that every field meta has the field/collection fields filled correctly
					payload.fields = payload.fields.map((field) => {
						if (field.meta) {
							field.meta = {
								...field.meta,
								field: field.field,
								collection: payload.collection!,
							};
						}

						// Add flag for specific database type overrides
						const flagToAdd = this.helpers.date.fieldFlagForField(field.type);

						if (flagToAdd) {
							addFieldFlag(field, flagToAdd);
						}

						return field;
					});

					const fieldsService = new FieldsService({ knex: trx, schema: this.schema });