When am placing an order (even from admin).. the order is created, but i get the following error:
Order saving error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (magento_db.catalog_product_entity, CONSTRAINT CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID FOREIGN KEY (attribute_set_id) REFERENCES eav_attribute_set (attribute_set_id) ON ), query was: INSERT INTO catalog_product_entity (entity_id, sku, has_options, required_options) VALUES (?, ?, ?, ?)
any idea how to solve this ?
googling didnt help
Related
We are facing org.springframework.dao.DataIntegrityViolationException while trying to insert the data into “BATCH_JOB_INSTANCE” table using spring batch2.0.
This issue does not occurs frequently on our system .It occurs randomly in our test environment. We are using SQL server database server.
Below error message is writing to logs :-
[PreparedStatementCallback; SQL [INSERT into BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)]; Violation of PRIMARY KEY constraint 'PK__BATCH_JO__4848154AB1CB6AD0'. Cannot insert duplicate key in object 'dbo.BATCH_JOB_INSTANCE'. The duplicate key value is (402).; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK__BATCH_JO__4848154AB1CB6AD0'. Cannot insert duplicate key in object 'dbo.BATCH_JOB_INSTANCE'. The duplicate key value is (402).; caused by Violation of PRIMARY KEY constraint 'PK__BATCH_JO__4848154AB1CB6AD0'. Cannot insert duplicate key in object 'dbo.BATCH_JOB_INSTANCE'. The duplicate key value is (402).] and cannot be retried automatically. The job must be manually recovered
org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [INSERT into BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)]; Violation of PRIMARY KEY constraint 'PK__BATCH_JO__4848154AB1CB6AD0'. Cannot insert duplicate key in object 'dbo.BATCH_JOB_INSTANCE'. The duplicate key value is (402).; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK__BATCH_JO__4848154AB1CB6AD0'. Cannot insert duplicate key in object 'dbo.BATCH_JOB_INSTANCE'. The duplicate key value is (402).
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:228)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:607)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:792)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:850)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:854)
at org.springframework.batch.core.repository.dao.JdbcJobInstanceDao.createJobInstance(
We have also implemented the solution which is mention in below link.
https://github.com/spring-projects/spring-batch/issues/1232?jql=project%2520%253D%2520BATCH%2520AND%2520text%2520~%2520%2522key%2522
We thought it to be a database issue and asked team to recreate the database. Issue is still appearing after database recreate as well.
We found some details from the spring jira and found that you have worked on similar issues earlier. If you could provide us any insight we will be thankful.
We have done some changes mentioned earlier and none is helping us. If you could provide us with some pointers that will be helpful.
I have a foreign key constraint on a table and when I’m inserting data I get the following error:
ERROR: insert or update on table "gl_account_item" violates foreign key constraint "fk_gl_account_id" DETAIL: Key (gl_account_id)=(939) is not present in table "gl_account". SQL state: 23503
…if I query the table I can clearly see that it is:
Here is the CREATE TABLE statement:
I cannot understand why I'm getting a foreign key constraint violation error when the id is clearly there in the primary key table. If I remove the foreign key constraint and insert the data and put the constraint back and run a query with a join on that field everything works and the data is there:
Please help.
I am using magento2. there is showing an error "SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails". How I can fix this please help.
please check the screen short of error :- http://prntscr.com/k48rpk
I am new to SQL and am attempted to create a table, then alter the table to add some constraints with ALTER and finally insert 2 employees, one managing the other.
I have been getting this error in pgAdmin4 "ERROR: syntax error at or near "INSERT"
If anyone could let me know any other obvious issues in my code that would be great
Here is the table:
CREATE TABLE employee (
emp_id integer NOT NULL,
first_name varchar(15) NOT NULL,
last_name varchar(15) NOT NULL,
manager integer
);
And the altering:
ALTER TABLE employee ADD CONSTRAINT unique_emp_id UNIQUE (emp_id);
ALTER TABLE employee ADD FOREIGN KEY (manager) REFERENCES emp_id;
ALTER TABLE employee ADD CHECK (emp_id != manager)
INSERT INTO employee VALUES
(1, 'Tom', 'Jones', 2);
INSERT INTO employee (emp_id, first_name, last_name)
VALUES (2, 'Dave', 'Smith');
The foreign key reference needs to mention the table, even for a self-reference:
ALTER TABLE employee ADD FOREIGN KEY (manager) REFERENCES employee(emp_id);
In addition, the first insert doesn't work because the table is empty, so the foreign key fails. The inserts are in the wrong order. You should also list all the columns for an insert, even when you think you know them.
Here is a SQL Fiddle with the rest of the statements working.
This is the situation: I have two tables where the one references the other (say, table2 references table1). When creating these tables, I did set the foreign key constraint as DEFERRABLE and the ON UPDATE and ON DELETE clauses as NO ACTION (which is the default).
But still, when running the transaction below, I get the following error.
Transaction:
START TRANSACTION;
SET CONSTRAINTS ALL DEFERRED;
UPDATE table1 SET blah blah;
UPDATE table2 SET blah blah;
COMMIT;
Error:
ERROR: update or delete on table "table1" violates foreign key constraint "table1_column_fkey" on table "table2"
DETAIL: Key (column1)=(blahblah) is still referenced from table "table2".
And table construction:
CREATE TABLE table1(
column1 CHAR(10),
[...]
PRIMARY KEY (column1)
);
CREATE TABLE table2(
primkey CHAR(9),
[...]
column2 CHAR(10) NOT NULL,
PRIMARY KEY(primkey),
FOREIGN KEY(column2) REFERENCES table1(column1) DEFERRABLE
);
What I want to do is to defer the foreign key checking while the transaction is in progress, until it commits. I just can't see why is this error returning and how can I make the transaction work.
The problem was indeed a foreign key constraint violation. I mean, the constraints were indeed deferred within the transaction, but the problem was that at the end of the transaction, after table1 and table2 were updated, the new data were violating a foreign key constraint. I was updating the primary key of a table1 row, which was still being referenced by some table2 rows. These rows I had to update them too, so that the referencing column of table2 rows matched the updated primary key of table1's row. I changed the 'UPDATE' queries within the transaction and the problem got solved.
Sorry to put you into this. The solution was so simple, but that day I coudn't see it.