ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

I can't create Customers with duplicate 'Customer Name'

I changed Customer Naming By in Selling Setting to use naming series and the ‘Unique’ checkbox under Customer Name field is not selected so why am I not able to create customers with the same Customer Name?

Hi there,

Name fields are special in ERPNext. They act as primary database keys, and likewise they must always be unique. If you want to be able to have duplicate customer names, you’ll need to use a series in Selling Settings for “Customer Naming By”.

Hi,

As mentioned in my original post I’ve already changed the ‘Customer Naming By’ in Selling settings to use naming series but I am still having this issue.

This is the traceback from the ‘Customer Name Must Be Unique’ error I get when trying to import customers with duplicate name.

Any help is appreciated I have been stuck on this for days now.
Thanks.

My apologies, I misread your first post. First, just to confirm, this is v13?

There’s something very weird happening with your database. I don’t know why you have a key called “customer_name_2”. My hunch would be that you’ve got a custom field of some sort that is conflicting. Can you show your field list from the customize form tool?

To troubleshoot, let’s try to isolate the problem. Imports can be tricky sometimes. What happens when you try to create a customer with an identical “Full Name” manually?

Hi,

Yes this is V13 I also just updated to the latest release two days ago. I was confused when I saw customer_name_2 as well. Here is all the fields in customer:


When I create a customer with identical name I get the error message I showed in my original post. I think I changed the ‘Full Name’ field to be ‘Customer Name’ instead, is that something that would cause this error?

If you just changed the label (and not the actual field name), it shouldn’t cause any problems.

When you get that error message, do you get a stack trace in your browser console? Please test by creating a new customer manually from the app, not by import.

1 Like

This is the entire stack trace from the console after I create a Customer with duplicate name manually.

Hmm…nothing is jumping out at me. Something is creating the field customer_name_2. If you try to access that key via javascript from the console while viewing a form (cur_frm.doc.customer_name_2), does anything pop up?

Beyond that, I can’t really explain. It might be a custom field or custom script of some type interfering. I just can’t reproduce the issue on my machine.

Nope says its undefined:
00%20AM

So is there anyway I can reset this or something because I really need to create customers with duplicate names otherwise I will need to stop using this system.

I don’t have any custom scripts and I showed you all the custom fields I have so I don’t think that is the problem.

Hmm…I’m stumped. Have you changed the naming section on the form customization tool?

You can reset form customizations from the upper right corner of the tool itself, I believe. If that doesn’t work, I’m afraid I’m completely out of ideas. :frowning:

I did play around with the Naming a bit but it’s set as ‘naming_series:’ now.

Tried resetting the form customizations but that didn’t do anything really, still getting the same problem. Is there any other way I can reset the whole doctype or something? or is my only option to reinstall the site and start from scratch and hope this error doesn’t happen again. I’ve spent everyday the last month setting up and trying to convert all my business processes to this system so I really want this to work. :frowning_face:

Yeah, I am really frustrated on your behalf. There’s got to be a way to get this working. The challenge is that I can’t reproduce the error on my machine, so it’s tricky to troubleshoot.

If you feel comfortable sending me a copy of your database, I can try to spin it up in a development environment to see if I can drill into the error a bit. I can fully understand why you might not want to do that, of course.

Otherwise, I’m happy to keep throwing ideas around. I’ve got a few different theories, but they’re all pretty weak. This thread describes the same error message related to Contact creation. That’d be one place to potentially explore.

Okay I don’t mind sending you a copy, how should I send it to you?

go to custom field list, search for doctype Customer, see whether there is customer_name_2 custom field defined for DocType Customer, untick the unique property. or simply delete this custom field.

There is no such field I even searched for this column name across the entire database using mariadb console and there is no column name for customer_name_2.

The good news is that I’ve found the problem. For some reason, you’ve got an extra key on your Customer table:

I’m kicking myself a bit, because that’s exactly what the error message was telling us. I assumed that the keys and fields were matching, but somehow they got out of sync. My guess would be that a database command got interrupted somehow or failed for some other reason, and the application didn’t catch it.

It should be an easy fix, though it does require direct manipulation of the database. Use appropriate caution for that, of course:

ALTER TABLE `tabCustomer` DROP INDEX `customer_name_2`;

I’ll look into how some kind of index check might be added to catch this problem in the future, though my knowledge of the database driver is pretty thin. It’s one of those things that shouldn’t ever happen, but evidently it can happen in some edge circumstances.

2 Likes

Ohh now I see why it didn’t show up in my query. Thank you so much for your help!

1 Like