#28000: Migration forces "DROP DEFAULT" SQL -----------------------------------------------+------------------------ Reporter: Matteo Pietro Russo | Owner: nobody Type: Bug | Status: new Component: Migrations | Version: 1.9 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -----------------------------------------------+------------------------ If i consider to modify a column (ChaField) to add a default value as follow:
from django.db import models class PersonModel(models.Model): nickname = models.CharField(default="noname", max_length=100, null=False) makemigration insists on creating a new migration for this change. However, the migration on MYSQL shows: BEGIN; ALTER TABLE "core_personmodel" ALTER "nickname" SET DEFAULT 'noname'; ALTER TABLE "core_personmodel" ALTER "nickname" DROP DEFAULT; COMMIT; I think there is a mistake at line 735 in django/db/backends/base/schema.py {{{ # Drop the default if we need to # (Django usually does not use in-database defaults) if needs_database_default: sql = self.sql_alter_column % { "table": self.quote_name(model._meta.db_table), "changes": self.sql_alter_column_no_default % { "column": self.quote_name(new_field.column), } } self.execute(sql) }}} If I "needs_database_default", why we need to drop default (sql_alter_column_no_default)? I read we use it to prevent extraneous DROP DEFAULT statements (an example is LONGTEXT in MySQL) because if database is able to use default we need to avoid to drop it. -- Ticket URL: <https://code.djangoproject.com/ticket/28000> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.f68b8f5a1c16da0e05959e6cc7a309c1%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.