Question: Why are Unique Dates a forbidden DocField?

While creating a new DocField, I marked the ‘Unique’ checkbox. But the DocType would not save, due to this error:

Fieldtype Date for MyDateField cannot be unique”:

So I checked the Frappe code in Apparently only 3 types can be made unique:

  • Data
  • Link
  • Read Only

To keep making progress on my project, I’m going to edit the Frappe code, and allow for Dates.

But does anyone know/remember the reasoning behind this limitation?


What happens if you create two documents of the same doctype in the same day ?

Why would you want to make date unique ?

Would adding code in validate hook of the document to identify unique violations be an alternative to editing Frappe code?

@olamide_shodunke This isn’t a Creation Date. It’s just a custom field I added, of type = Date, that must be unique for all records in the table.

Sure, that’s an alternative way of enforcing uniqueness.

This was intended as a “why” thread. That perhaps someone knew a good reason why this limitation exists in the current code.

I normally don’t ask “why” questions, because it’s extremely rare that anyone has the answer.
But I was feeling lucky yesterday. :slight_smile:

1 Like

Your date field is a custom field means it’s only you are using it for your specific purpose and maybe in a specific doctype.

So I believe because date as DocField in general would be too risky to be made unique for the reason @olamide_shodunke said.
And interesting to see if you change the code in frappe, what happen to the all other doctypes using date field.

None of the other Date fields have their ‘Unique’ checkbox marked. Because it’s forbidden.
So nothing should happen.

SELECT * FROM tabDocField
    fieldtype = 'Date' AND `unique` = 1

-- No Results

You’re right.
Maybe if the other ‘Unique’ checkbox is accidentally checked then problem may arise.