Skip to content

Exclude indexs when delete unique constrains #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 21, 2020

Conversation

henrikek
Copy link

@henrikek henrikek commented Apr 17, 2020

Django migrations 1 (add field undone)

migrations.AddField(
            model_name='processtask',
            name='undone',
            field=models.OneToOneField(blank=True, null=True, on_delete=models.SET_NULL, related_name='undone_task', to='WorkflowEngine.ProcessTask'),
)

Django migrations 2 (remove field undone)

migrations.RemoveField(
            model_name='processtask',
            name='undone',
)

Problem description, delete_unique tries to remove a constraint that has already been deleted. See results below:

constraints - 'ProcessTask_undone_id_9a3b7af0_uniq': {'columns': ['undone_id'], 'primary_key': False, 'unique': True, 'foreign_key': None, 'check': False, 'index': True, 'orders': ['ASC'], 'type': 'idx'}

delete_constraint:
ALTER TABLE [ProcessTask] DROP CONSTRAINT ProcessTask_undone_id_9a3b7af0_fk_ProcessTask_id]

delete_index:
DROP INDEX [ProcessTask_undone_id_9a3b7af0_uniq] ON [ProcessTask]

delete_unique:
ALTER TABLE [ProcessTask] DROP CONSTRAINT [ProcessTask_undone_id_9a3b7af0_uniq]

Traceback (most recent call last):

  File "C:\ESSArch\pd\python\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "C:\ESSArch\pd\python\lib\site-packages\sql_server\pyodbc\base.py", line 555, in execute
    return self.cursor.execute(sql, params)
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]'ProcessTask_undone_id_9a3b7af0_uniq' is not a constraint. (3728) (SQLExecDirectW); [42000] Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Could not drop constraint. See previous errors. 3727)")

@henrikek henrikek requested a review from OskarPersson April 17, 2020 16:48
@OskarPersson
Copy link
Collaborator

A test demonstrating the change should be added before merging this.

Also, please use proper text formatting in the description to make it more readable, it's quite difficult to follow it as it is right now.

@henrikek
Copy link
Author

I have now updated the described text with better formatting and code blocks.

I'm not sure how to make a good test case besides the description of this PR.

@OskarPersson
Copy link
Collaborator

OskarPersson commented Apr 17, 2020

See #39 and #47 (might be related to this PR) for examples on writing tests

@henrikek
Copy link
Author

Added test migrations 👍 The successful running of the 2 new test migrations should be sufficient to test this PR.

@OskarPersson
Copy link
Collaborator

Just the lint errors left :)

@henrikek
Copy link
Author

Fixed :)

@OskarPersson OskarPersson merged commit 76a1317 into master Apr 21, 2020
@henrikek henrikek deleted the RemoveField-constraint branch April 22, 2020 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants