During our upgrade process I've found that DO tries to delete data from droppped table before actually droppping them. This is really WRONG. First we need to drop FKs/Columns other referencing object, then delete the data if any.

var batch = 

In our case this lead to inability to perform an upgrade at all.

Xtensive.Orm.ReferentialConstraintViolationException: SQL error occured.
Storage error details 'Entity: Mortgage;'
SQL error details 'Type: ReferentialConstraintViolation; Database: Eis; Table: Mortgage; Column: ReasonOfMortgage_Id; Constraint: FK_Mortgage-ReasonOfMortgage-ReasonOfMortgage_ReasonOfMortgage;'
Query 'DELETE FROM [dbo].[ReasonOfMortgage];
DELETE FROM [dbo].[SubaccountWithoutStorage];
DELETE FROM [dbo].[ParCredentials];
DELETE FROM [dbo].[ParCredentialsForUser];
DELETE FROM [dbo].[TypeOfAuthority];
DELETE FROM [dbo].[Mortgage_TpPayment];
DELETE FROM [dbo].[Mortgage_TpFine];
DELETE FROM [dbo].[EntityIndex];
DELETE FROM [dbo].[ParLinkedEntityes];
DELETE FROM [dbo].[PersonRoleParametr];
DELETE FROM [dbo].[EntityIndex_MlIndexField];
DELETE FROM [dbo].[RegIsExchangeFoundation];'
Original message 'The DELETE statement conflicted with the REFERENCE constraint "FK_Mortgage-ReasonOfMortgage-ReasonOfMortgage_ReasonOfMortgage". The conflict occurred in database "Eis", table "dbo.Mortgage", column 'ReasonOfMortgage_Id'.
The statement has been terminated.'

asked Oct 06 '11 at 09:48

xumix's gravatar image


edited Oct 06 '11 at 09:51

Dmitri%20Maximov's gravatar image

Dmitri Maximov

I've just sent you the test project and db backup

(Oct 06 '11 at 12:00) xumix xumix's gravatar image

I've sent you another simplified test with DB backup. Now it fails with foreign key whaen updating a table

(Oct 20 '11 at 07:45) xumix xumix's gravatar image

How kind of you =)

(Oct 20 '11 at 08:28) Dmitri Maximov Dmitri%20Maximov's gravatar image

One Answer:

Latest nightly build contains several fixes for this issue:

  • Foreign keys and unique indexes are dropped before update statements
  • Foreign keys and unique indexes are created at very late stage, so you can modify any relevant data in OnUpgrade() method

answered Nov 01 '11 at 14:19

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov

edited Nov 01 '11 at 14:19

UPD: Nightly builds are not updated yet, so this fix IS NOT there. If you have access to our source code repository, you can build fixed version yourself. Otherwise, please wait until fix is released to public.

(Nov 02 '11 at 11:01) Denis Krjuchkov Denis%20Krjuchkov's gravatar image

Well, new troubles. Case: Mark type as recycled, mark the referencing field as recycled. Try to use recycled field value in OnUpgrade - get null values for all rows.

(Nov 18 '11 at 02:33) xumix xumix's gravatar image

Well, let's open a separate issue for that case.


(Nov 18 '11 at 02:36) Dmitri Maximov Dmitri%20Maximov's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA