2

I created one custom attibute for customer. and make unique value true. while we edit customer in admin panel , and trying to save, its always give error like attribute should be unique. but their value is already unique.

I created the attribute like this:

if(version_compare($context->getVersion(), '1.1.9','<')) {
        $customerSetup->addAttribute(Customer::ENTITY, 'mobile_number', [
                'type' => 'text',
                'label' => 'Mobile Number',
                'input' => 'text',
                'backend' => '',
                'frontend' => '',
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
                'required' => false,
                'visible' => true,
                'user_defined' => false,
                'unique' => true,
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'position' => 112,
                'system' => 0,
                'source' => ''
        ]);

        $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'mobile_number')
        ->addData([
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => ['adminhtml_customer','customer_account_edit'],

        ]);

        $attribute->save();
     }
3

Can you please mention which magento version you are using because i found it is known bug and get resolved in magento 2.2.x

https://github.com/magento/magento2/issues/7844

  • I am using magento 2.1.5 – sam Jun 14 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.