Magento 2 : Unique constraint violation found when adding product, categories or mega menu items
I have a Magento 2.2.3 installation and I have the theme SM-Maxshop on that. I am not able to add any products, categories or Megamenu items to it. I get an error "Unique constraint violation found" when I do any of these operations. I was able to add custom product attributes and add them to attribute sets too, but am stuck after that. Has anyone else faced any issue like this?
PFA screenshots of the error pages.
I see this in the exception.log file:
I see this entry in exception.log:
[2018-05-14 05:36:06] main.CRITICAL: Unique constraint violation
found {"exception":"[object]
(MagentoFrameworkExceptionAlreadyExistsException(code: 0):
Unique constraint violation found at
/home/.../public_html/.../vendor/magento/framework/EntityManager/Operation/Create.php:134,
MagentoFrameworkDBAdapterDuplicateException(code: 1062):
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
'0' for key 'PRIMARY', query was: INSERT INTOurl_rewrite
(redirect_type
,is_autogenerated
,metadata
,description
,store_id
,entity_type
,entity_id
,request_path
,target_path
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?,
?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?,
?, ?, ?, ?) at
/home/.../public_html/.../vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:555,
Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity
constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY',
query was: INSERT INTOurl_rewrite
(redirect_type
,is_autogenerated
,metadata
,description
,store_id
,entity_type
,entity_id
,request_path
,target_path
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?,
?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?,
?, ?, ?, ?) at
/home/.../public_html/.../vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:235,
PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint
violation: 1062 Duplicate entry '0' for key 'PRIMARY' at
/home/.../public_html/.../vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228)"}
database url-rewrite magento2.2.3
add a comment |
I have a Magento 2.2.3 installation and I have the theme SM-Maxshop on that. I am not able to add any products, categories or Megamenu items to it. I get an error "Unique constraint violation found" when I do any of these operations. I was able to add custom product attributes and add them to attribute sets too, but am stuck after that. Has anyone else faced any issue like this?
PFA screenshots of the error pages.
I see this in the exception.log file:
I see this entry in exception.log:
[2018-05-14 05:36:06] main.CRITICAL: Unique constraint violation
found {"exception":"[object]
(MagentoFrameworkExceptionAlreadyExistsException(code: 0):
Unique constraint violation found at
/home/.../public_html/.../vendor/magento/framework/EntityManager/Operation/Create.php:134,
MagentoFrameworkDBAdapterDuplicateException(code: 1062):
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
'0' for key 'PRIMARY', query was: INSERT INTOurl_rewrite
(redirect_type
,is_autogenerated
,metadata
,description
,store_id
,entity_type
,entity_id
,request_path
,target_path
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?,
?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?,
?, ?, ?, ?) at
/home/.../public_html/.../vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:555,
Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity
constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY',
query was: INSERT INTOurl_rewrite
(redirect_type
,is_autogenerated
,metadata
,description
,store_id
,entity_type
,entity_id
,request_path
,target_path
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?,
?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?,
?, ?, ?, ?) at
/home/.../public_html/.../vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:235,
PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint
violation: 1062 Duplicate entry '0' for key 'PRIMARY' at
/home/.../public_html/.../vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228)"}
database url-rewrite magento2.2.3
Please check system.log and paste relevant info here.
– Vivek Kumar
May 14 '18 at 5:24
I did not see anything relevant in system.log. But pasted the error from exception.log
– Priyanka
May 14 '18 at 5:42
How many products do you have in your db?
– Vivek Kumar
May 14 '18 at 5:49
Only 6 right now. I have added custom attributes and created attribute sets though.
– Priyanka
May 14 '18 at 6:06
add a comment |
I have a Magento 2.2.3 installation and I have the theme SM-Maxshop on that. I am not able to add any products, categories or Megamenu items to it. I get an error "Unique constraint violation found" when I do any of these operations. I was able to add custom product attributes and add them to attribute sets too, but am stuck after that. Has anyone else faced any issue like this?
PFA screenshots of the error pages.
I see this in the exception.log file:
I see this entry in exception.log:
[2018-05-14 05:36:06] main.CRITICAL: Unique constraint violation
found {"exception":"[object]
(MagentoFrameworkExceptionAlreadyExistsException(code: 0):
Unique constraint violation found at
/home/.../public_html/.../vendor/magento/framework/EntityManager/Operation/Create.php:134,
MagentoFrameworkDBAdapterDuplicateException(code: 1062):
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
'0' for key 'PRIMARY', query was: INSERT INTOurl_rewrite
(redirect_type
,is_autogenerated
,metadata
,description
,store_id
,entity_type
,entity_id
,request_path
,target_path
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?,
?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?,
?, ?, ?, ?) at
/home/.../public_html/.../vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:555,
Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity
constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY',
query was: INSERT INTOurl_rewrite
(redirect_type
,is_autogenerated
,metadata
,description
,store_id
,entity_type
,entity_id
,request_path
,target_path
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?,
?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?,
?, ?, ?, ?) at
/home/.../public_html/.../vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:235,
PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint
violation: 1062 Duplicate entry '0' for key 'PRIMARY' at
/home/.../public_html/.../vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228)"}
database url-rewrite magento2.2.3
I have a Magento 2.2.3 installation and I have the theme SM-Maxshop on that. I am not able to add any products, categories or Megamenu items to it. I get an error "Unique constraint violation found" when I do any of these operations. I was able to add custom product attributes and add them to attribute sets too, but am stuck after that. Has anyone else faced any issue like this?
PFA screenshots of the error pages.
I see this in the exception.log file:
I see this entry in exception.log:
[2018-05-14 05:36:06] main.CRITICAL: Unique constraint violation
found {"exception":"[object]
(MagentoFrameworkExceptionAlreadyExistsException(code: 0):
Unique constraint violation found at
/home/.../public_html/.../vendor/magento/framework/EntityManager/Operation/Create.php:134,
MagentoFrameworkDBAdapterDuplicateException(code: 1062):
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
'0' for key 'PRIMARY', query was: INSERT INTOurl_rewrite
(redirect_type
,is_autogenerated
,metadata
,description
,store_id
,entity_type
,entity_id
,request_path
,target_path
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?,
?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?,
?, ?, ?, ?) at
/home/.../public_html/.../vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:555,
Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity
constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY',
query was: INSERT INTOurl_rewrite
(redirect_type
,is_autogenerated
,metadata
,description
,store_id
,entity_type
,entity_id
,request_path
,target_path
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?,
?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?,
?, ?, ?, ?) at
/home/.../public_html/.../vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:235,
PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint
violation: 1062 Duplicate entry '0' for key 'PRIMARY' at
/home/.../public_html/.../vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228)"}
database url-rewrite magento2.2.3
database url-rewrite magento2.2.3
edited May 14 '18 at 6:20
Rama Chandran M
2,71181430
2,71181430
asked May 14 '18 at 2:49
PriyankaPriyanka
12
12
Please check system.log and paste relevant info here.
– Vivek Kumar
May 14 '18 at 5:24
I did not see anything relevant in system.log. But pasted the error from exception.log
– Priyanka
May 14 '18 at 5:42
How many products do you have in your db?
– Vivek Kumar
May 14 '18 at 5:49
Only 6 right now. I have added custom attributes and created attribute sets though.
– Priyanka
May 14 '18 at 6:06
add a comment |
Please check system.log and paste relevant info here.
– Vivek Kumar
May 14 '18 at 5:24
I did not see anything relevant in system.log. But pasted the error from exception.log
– Priyanka
May 14 '18 at 5:42
How many products do you have in your db?
– Vivek Kumar
May 14 '18 at 5:49
Only 6 right now. I have added custom attributes and created attribute sets though.
– Priyanka
May 14 '18 at 6:06
Please check system.log and paste relevant info here.
– Vivek Kumar
May 14 '18 at 5:24
Please check system.log and paste relevant info here.
– Vivek Kumar
May 14 '18 at 5:24
I did not see anything relevant in system.log. But pasted the error from exception.log
– Priyanka
May 14 '18 at 5:42
I did not see anything relevant in system.log. But pasted the error from exception.log
– Priyanka
May 14 '18 at 5:42
How many products do you have in your db?
– Vivek Kumar
May 14 '18 at 5:49
How many products do you have in your db?
– Vivek Kumar
May 14 '18 at 5:49
Only 6 right now. I have added custom attributes and created attribute sets though.
– Priyanka
May 14 '18 at 6:06
Only 6 right now. I have added custom attributes and created attribute sets though.
– Priyanka
May 14 '18 at 6:06
add a comment |
3 Answers
3
active
oldest
votes
You should TRUNCATE tables catalog_url_rewrite_product_category and URL_rewrite and you can recreate the required url keys by just resaving all the categories.
I hope this will resolve your problem. Just in case keep a backup of your tables.
EDIT:
After looking at your complete stack trace, I am pretty sure some module is running a oberver/plugin/preference at product and category save at setting url_key to 0 value.It will give error as url_key should be unique for every product and category.
Please check this and update.
I tried this, but it did not work. I still get the same error and exception.log also has same entry :(
– Priyanka
May 14 '18 at 6:43
Please check edit
– Vivek Kumar
May 14 '18 at 7:55
add a comment |
SOLVED Invoice Unique Constraint Violation Magento 2.2.5 when i am generating a invoice facing this error
Just go to data base -> sales_invoice -> indexes just remove one rule "SALES_INVOICE_INCREMENT_ID_STORE_ID '
Removing indexes is a very bad idea. It will allow you to create multiple invoices with the same increment id which can later on break other processes, such as payment integrations.
– Alex Dinca
Dec 17 '18 at 12:56
add a comment |
This is most likely an issue with a primary key field. Make sure that auto increment is present for such a field. If it's missing, you can simply add it by running SQL queries:
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE your_table_name MODIFY your_field_name INTEGER NOT NULL AUTO_INCREMENT;
SET FOREIGN_KEY_CHECKS=1;
Also, you can change the autoincrement value and set it bigger, so the next created item will have a higher ID.
In my case, I have had the error "Unique constraint violation found" in Magento 2 Blog extension by Magefan on one of my projects when I tried to add a new blog post and save it. For some reason, table magefan_blog_post has not had increment setting for post ID. I fixed this by running this SQL queries:
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE magefan_blog_post MODIFY post_id INTEGER NOT NULL AUTO_INCREMENT;
SET FOREIGN_KEY_CHECKS=1;
The strange is that on other Magento instance there was no issue, so I think that this is some glitches with the Magento installation.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f225812%2fmagento-2-unique-constraint-violation-found-when-adding-product-categories-or%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should TRUNCATE tables catalog_url_rewrite_product_category and URL_rewrite and you can recreate the required url keys by just resaving all the categories.
I hope this will resolve your problem. Just in case keep a backup of your tables.
EDIT:
After looking at your complete stack trace, I am pretty sure some module is running a oberver/plugin/preference at product and category save at setting url_key to 0 value.It will give error as url_key should be unique for every product and category.
Please check this and update.
I tried this, but it did not work. I still get the same error and exception.log also has same entry :(
– Priyanka
May 14 '18 at 6:43
Please check edit
– Vivek Kumar
May 14 '18 at 7:55
add a comment |
You should TRUNCATE tables catalog_url_rewrite_product_category and URL_rewrite and you can recreate the required url keys by just resaving all the categories.
I hope this will resolve your problem. Just in case keep a backup of your tables.
EDIT:
After looking at your complete stack trace, I am pretty sure some module is running a oberver/plugin/preference at product and category save at setting url_key to 0 value.It will give error as url_key should be unique for every product and category.
Please check this and update.
I tried this, but it did not work. I still get the same error and exception.log also has same entry :(
– Priyanka
May 14 '18 at 6:43
Please check edit
– Vivek Kumar
May 14 '18 at 7:55
add a comment |
You should TRUNCATE tables catalog_url_rewrite_product_category and URL_rewrite and you can recreate the required url keys by just resaving all the categories.
I hope this will resolve your problem. Just in case keep a backup of your tables.
EDIT:
After looking at your complete stack trace, I am pretty sure some module is running a oberver/plugin/preference at product and category save at setting url_key to 0 value.It will give error as url_key should be unique for every product and category.
Please check this and update.
You should TRUNCATE tables catalog_url_rewrite_product_category and URL_rewrite and you can recreate the required url keys by just resaving all the categories.
I hope this will resolve your problem. Just in case keep a backup of your tables.
EDIT:
After looking at your complete stack trace, I am pretty sure some module is running a oberver/plugin/preference at product and category save at setting url_key to 0 value.It will give error as url_key should be unique for every product and category.
Please check this and update.
edited May 14 '18 at 7:55
answered May 14 '18 at 6:11
Vivek KumarVivek Kumar
2,4242629
2,4242629
I tried this, but it did not work. I still get the same error and exception.log also has same entry :(
– Priyanka
May 14 '18 at 6:43
Please check edit
– Vivek Kumar
May 14 '18 at 7:55
add a comment |
I tried this, but it did not work. I still get the same error and exception.log also has same entry :(
– Priyanka
May 14 '18 at 6:43
Please check edit
– Vivek Kumar
May 14 '18 at 7:55
I tried this, but it did not work. I still get the same error and exception.log also has same entry :(
– Priyanka
May 14 '18 at 6:43
I tried this, but it did not work. I still get the same error and exception.log also has same entry :(
– Priyanka
May 14 '18 at 6:43
Please check edit
– Vivek Kumar
May 14 '18 at 7:55
Please check edit
– Vivek Kumar
May 14 '18 at 7:55
add a comment |
SOLVED Invoice Unique Constraint Violation Magento 2.2.5 when i am generating a invoice facing this error
Just go to data base -> sales_invoice -> indexes just remove one rule "SALES_INVOICE_INCREMENT_ID_STORE_ID '
Removing indexes is a very bad idea. It will allow you to create multiple invoices with the same increment id which can later on break other processes, such as payment integrations.
– Alex Dinca
Dec 17 '18 at 12:56
add a comment |
SOLVED Invoice Unique Constraint Violation Magento 2.2.5 when i am generating a invoice facing this error
Just go to data base -> sales_invoice -> indexes just remove one rule "SALES_INVOICE_INCREMENT_ID_STORE_ID '
Removing indexes is a very bad idea. It will allow you to create multiple invoices with the same increment id which can later on break other processes, such as payment integrations.
– Alex Dinca
Dec 17 '18 at 12:56
add a comment |
SOLVED Invoice Unique Constraint Violation Magento 2.2.5 when i am generating a invoice facing this error
Just go to data base -> sales_invoice -> indexes just remove one rule "SALES_INVOICE_INCREMENT_ID_STORE_ID '
SOLVED Invoice Unique Constraint Violation Magento 2.2.5 when i am generating a invoice facing this error
Just go to data base -> sales_invoice -> indexes just remove one rule "SALES_INVOICE_INCREMENT_ID_STORE_ID '
answered Sep 26 '18 at 8:24
mnojindmnojind
213
213
Removing indexes is a very bad idea. It will allow you to create multiple invoices with the same increment id which can later on break other processes, such as payment integrations.
– Alex Dinca
Dec 17 '18 at 12:56
add a comment |
Removing indexes is a very bad idea. It will allow you to create multiple invoices with the same increment id which can later on break other processes, such as payment integrations.
– Alex Dinca
Dec 17 '18 at 12:56
Removing indexes is a very bad idea. It will allow you to create multiple invoices with the same increment id which can later on break other processes, such as payment integrations.
– Alex Dinca
Dec 17 '18 at 12:56
Removing indexes is a very bad idea. It will allow you to create multiple invoices with the same increment id which can later on break other processes, such as payment integrations.
– Alex Dinca
Dec 17 '18 at 12:56
add a comment |
This is most likely an issue with a primary key field. Make sure that auto increment is present for such a field. If it's missing, you can simply add it by running SQL queries:
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE your_table_name MODIFY your_field_name INTEGER NOT NULL AUTO_INCREMENT;
SET FOREIGN_KEY_CHECKS=1;
Also, you can change the autoincrement value and set it bigger, so the next created item will have a higher ID.
In my case, I have had the error "Unique constraint violation found" in Magento 2 Blog extension by Magefan on one of my projects when I tried to add a new blog post and save it. For some reason, table magefan_blog_post has not had increment setting for post ID. I fixed this by running this SQL queries:
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE magefan_blog_post MODIFY post_id INTEGER NOT NULL AUTO_INCREMENT;
SET FOREIGN_KEY_CHECKS=1;
The strange is that on other Magento instance there was no issue, so I think that this is some glitches with the Magento installation.
add a comment |
This is most likely an issue with a primary key field. Make sure that auto increment is present for such a field. If it's missing, you can simply add it by running SQL queries:
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE your_table_name MODIFY your_field_name INTEGER NOT NULL AUTO_INCREMENT;
SET FOREIGN_KEY_CHECKS=1;
Also, you can change the autoincrement value and set it bigger, so the next created item will have a higher ID.
In my case, I have had the error "Unique constraint violation found" in Magento 2 Blog extension by Magefan on one of my projects when I tried to add a new blog post and save it. For some reason, table magefan_blog_post has not had increment setting for post ID. I fixed this by running this SQL queries:
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE magefan_blog_post MODIFY post_id INTEGER NOT NULL AUTO_INCREMENT;
SET FOREIGN_KEY_CHECKS=1;
The strange is that on other Magento instance there was no issue, so I think that this is some glitches with the Magento installation.
add a comment |
This is most likely an issue with a primary key field. Make sure that auto increment is present for such a field. If it's missing, you can simply add it by running SQL queries:
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE your_table_name MODIFY your_field_name INTEGER NOT NULL AUTO_INCREMENT;
SET FOREIGN_KEY_CHECKS=1;
Also, you can change the autoincrement value and set it bigger, so the next created item will have a higher ID.
In my case, I have had the error "Unique constraint violation found" in Magento 2 Blog extension by Magefan on one of my projects when I tried to add a new blog post and save it. For some reason, table magefan_blog_post has not had increment setting for post ID. I fixed this by running this SQL queries:
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE magefan_blog_post MODIFY post_id INTEGER NOT NULL AUTO_INCREMENT;
SET FOREIGN_KEY_CHECKS=1;
The strange is that on other Magento instance there was no issue, so I think that this is some glitches with the Magento installation.
This is most likely an issue with a primary key field. Make sure that auto increment is present for such a field. If it's missing, you can simply add it by running SQL queries:
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE your_table_name MODIFY your_field_name INTEGER NOT NULL AUTO_INCREMENT;
SET FOREIGN_KEY_CHECKS=1;
Also, you can change the autoincrement value and set it bigger, so the next created item will have a higher ID.
In my case, I have had the error "Unique constraint violation found" in Magento 2 Blog extension by Magefan on one of my projects when I tried to add a new blog post and save it. For some reason, table magefan_blog_post has not had increment setting for post ID. I fixed this by running this SQL queries:
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE magefan_blog_post MODIFY post_id INTEGER NOT NULL AUTO_INCREMENT;
SET FOREIGN_KEY_CHECKS=1;
The strange is that on other Magento instance there was no issue, so I think that this is some glitches with the Magento installation.
answered 2 days ago
lemk0lemk0
31828
31828
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f225812%2fmagento-2-unique-constraint-violation-found-when-adding-product-categories-or%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please check system.log and paste relevant info here.
– Vivek Kumar
May 14 '18 at 5:24
I did not see anything relevant in system.log. But pasted the error from exception.log
– Priyanka
May 14 '18 at 5:42
How many products do you have in your db?
– Vivek Kumar
May 14 '18 at 5:49
Only 6 right now. I have added custom attributes and created attribute sets though.
– Priyanka
May 14 '18 at 6:06