Exception when deleting an object - entity-framework-4.1

When I try to delete an object, I get a 'System.InvalidOperationException' with the following additional information:
The operation failed: The relationship could not be changed because
one or more of the foreign-key properties is non-nullable. When a
change is made to a relationship, the related foreign-key property is
set to a null value. If the foreign-key does not support null values,
a new relationship must be defined, the foreign-key property must be
assigned another non-null value, or the unrelated object must be
deleted.
How can I get more information? This message is like "something's wrong, but we are not going to reveal what"

The object/row you've tried to delete is probably a foreign key - the foreign key can't be null in the related table. Try deleting the other object/row first.
This issue would also happen if you tried to do this in SQL, you'd get:
The DELETE statement conflicted with the REFERENCE constraint 'FK_foo_bar'. The conflict occured in database...

Related

SQLAlchemy disable cascade on a relationship

In my database I have a view called my_view. I use the view to join it with another table my_table. Cause I don't now a way to map a view with the orm-mapper of SQLAlchemy, I mapped my_view like any other table. I give the primary-key in the relationship definition:
some_value = relationship("MyView", primaryjoin=my_view_id == MyView.id, useList=False)
This for fine, until I try to delete from my_table. The error is:
AssertionError: Dependency rule tried to blank-out primary key column 'my_view.id' on Instance '<MyView at 0x...>'
I am sure, the error happens, cause the mapper tries to delete a row from my_view. I found the cascade parameter, but I don't find out how I can stop it.
You can use the relationship option: passive_deletes="all"
See https://docs-sqlalchemy.readthedocs.io/ko/latest/orm/relationship_api.html#sqlalchemy.orm.relationship.params.passive_deletes
Additionally, setting the flag to the string value ‘all’ will disable
the “nulling out” of the child foreign keys, when there is no delete
or delete-orphan cascade enabled. This is typically used when a triggering
or error raise scenario is in place on the database side.

MySQL: can't insert a record because a foreign key issue

I have this schema
when i'm trying to add a new isp_share record I get this error
although isp table has a record with id=3
what could be the problem?
From documentation
http://dev.mysql.com/doc/refman/5.0/en/create-table-foreign-keys.html
The parent and child tables must use the same storage
engine..Corresponding columns in the foreign key and the referenced
key must have similar data types
Also do a check of the other tables.

Mysql cannot add or update child row, Foreign key related failure

Error: cannot add or update a child row: foreign key constraint fails
Following is the code that is creating the error:
ALTER TABLE 'catalog_eav_attribute'
ADD CONSTRAINT 'FK_CATALOG_EAV_ATTRIBUTE_ID'
FOREIGN KEY ('attribute_id') REFERENCES 'eav_attribute' ('attribute_id)'
ON DELETE CASCADE ON UPDATE CASCADE;
I uploaded the Structure of SQL and its has no issue , but when i insert the data i am getting the above related error. I read somewhere and i predict its because of lousy data.What are the other possibilities for the error ? Any suggestions or solution will be great.
"For storage engines other than InnoDB, MySQL Server parses the FOREIGN KEY syntax in CREATE TABLE statements, but does not use or store it."
From: http://dev.mysql.com/doc/refman/5.5/en/ansi-diff-foreign-keys.html
I'm not sure, but if your table is MyISAM and not InnoDB, your syntax might not work.
The error message means whatever number you're trying to put into the attribute_id column doesn't yet exist in the eav_attribute.attribute_id column.
Can you insert a value that does already exist in eav_attribute.attribute_id? (You probably can.)
Can you provoke the same error by trying to insert a value that doesn't exist in eav_attribute.attribute_id?
Reconcile the differences, and you're done. You need to determine which attribute ids don't exist in eav_attribute.attribute_id, and fix that.

primefaces in-cell editing on a table with compound primary key

I'm using primefaces 3.2 in-cell editing component to update an oracle DB table having compound primary key. The user should be able to edit also the primary key values but in this way if I use
em.merge(entity);
I got the following error
Exception [EclipseLink-7251] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [voce] of class [entity.competenze_distaccati.CompetenzeDistaccatiPK] is mapped to a primary key column in the database. Updates are not allowed.
...which sounds reasonable to me. The question is: How can I give the user the possibility to change also the primary key values?
rowEdit event listener is called with the changed value so I don't know which was the original record to perform a delete-insert.
Allowing modification of Primary Key is not Correct Way of handling the data. Instead, allow for deletion and add the record again with required values. This way, you will be following the standards and also, your problem gets solved.

violation of primary key constraint .Cannot insert duplicate key in object using ADO

we are working on a users apllication using Access2003(VBA) as software language and SQL Server 2005 as database.
We are using ADO method and we encounter a problem.
when users create new record in a ADO Screen and they want to save the record after implementing it they receive this error :
error -2147217873 violation of primary key constraint 'PK_ '.Cannot insert duplicate key in object 'Pk_...'
Any help will be appreciated
Thanks in advance
The problem occures since you can't have two primary keys with the same value.
If you are using Ints as primary key, remember to put auto-increment on it.
If you are using GUID as primary key, you might forget to set the guid to sometheing else than the default empty guid, and there by trying to insert and empty guid twice.
Are you trying to insert a new record with the primary key field having a value that is already in the database. The primary key field must always contain unique values.
Check witch columnt is your PrimaryKey. If you are trying to insert value that already exist then you are getting that error.
you should create your PK value either from your code or on the SQL side. On the SQL side, when creating your database, you have to indicate that default value for "myPrimaryKey" field is uniqueIdentifier, while from code, you could have something like
myRecordset.fields("myPrimaryKey") = stGuidGen()
(check here for the stGuidGen function)
There are some pros and cons to each method. By implementing the SQL method, you do not have to care about generating PKs anymore. By doing it through code, you can store the newly generated value without having to requery the database, and reuse it immediatly in your code, and this can be very useful.
get the property of your primary key column and set the identity property to YES