django-pyodbc-azure icon indicating copy to clipboard operation
django-pyodbc-azure copied to clipboard

Enumerate and remove DEFAULT constraints

Open bobince opened this issue 10 years ago • 3 comments
trafficstars

SQL Server implements in-database DEFAULT conditions as constraints, and requires that they be explicitly dropped before allowing the related column to be removed. Extend introspection to detect these constraints and return them as a new constraint type. Make the schema editor read and remove these constraints when removing a column.

Django doesn't generally use in-database DEFAULTs, but they can exist in legacy databases other tools have touched. For example: old versions of South would accidentally leave defaults in place after a migration to make a nullable column non-nullable. This can cause unexpected migration failures trying to delete the column later on.

bobince avatar Aug 04 '15 14:08 bobince

FYI, there are discussions going on now, on the django-developers mailing list, looking to add use of database defaults to Django. I would take a good look at the suggestions there to make sure you aren't going against the direction of evolution of Django. https://groups.google.com/d/topic/django-developers/3mcro17Gb40/discussion

shaib avatar Aug 04 '15 18:08 shaib

FWIW db_default is now a thing https://code.djangoproject.com/ticket/470#comment:69 (https://docs.djangoproject.com/en/dev/ref/models/fields/#db-default) though not yet released - presumably coming in Django 5.x

Something like this PR may need to be done over on https://github.com/microsoft/mssql-django/ to support this EDIT: filed https://github.com/microsoft/mssql-django/issues/302

sparrowt avatar Sep 18 '23 09:09 sparrowt