Skip to content

Fixed dropping foreign keys from tables on schemas #383

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mssql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
FROM sys.foreign_keys
WHERE referenced_object_id = object_id('%(table)s')
SELECT
@sql_drop_constraint = 'ALTER TABLE [' + OBJECT_NAME(parent_object_id) + '] ' +
@sql_drop_constraint = 'ALTER TABLE [' + sch.name + '].[' + OBJECT_NAME(parent_object_id) + '] ' +
'DROP CONSTRAINT [' + @sql_foreign_constraint_name + '] '
FROM sys.foreign_keys
WHERE referenced_object_id = object_id('%(table)s') and name = @sql_foreign_constraint_name
exec sp_executesql @sql_drop_constraint
FROM sys.foreign_keys fk
INNER JOIN sys.schemas sch ON fk.schema_id = sch.schema_id
WHERE fk.referenced_object_id = object_id('%(table)s') and fk.name = @sql_foreign_constraint_name
END
DROP TABLE %(table)s
"""
Expand Down
Loading