#25105: Migrating multiple CharFields to null=False breaks on PostgreSQL ----------------------------+------------------------------------ Reporter: danielr | Owner: nobody Type: Bug | Status: new Component: Migrations | Version: 1.8 Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ----------------------------+------------------------------------
Comment (by danielr): On further investigation, in turns out that a) you do need at least two fields being migrated, and b) you also need a {{{ForeignKey}}}, which is why Zanuda999 couldn't replicate it. So, given these models: {{{ class Model1(models.Model): field1 = models.CharField(max_length=20) class Model2(models.Model): field1 = models.CharField(max_length=20, blank=True, null=True) field2 = models.CharField(max_length=20, blank=True, null=True) model1 = models.ForeignKey(Model1) }}} Create and run the migrations, then in the shell: {{{ >>> m=Model1.objects.create(field1='foo') >>> Model2.objects.create(model1=m) }}} Now, delete the {{{null=True}}} from Model2.field1 and field2, and create migrations again, using a one-off default of {{{''}}} for both fields. Running migrations now produces this error: {{{ Running migrations: Rendering model states... DONE Applying null_to_blank.0002_auto_20150711_1244...Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/danielroseman/Projects/django/django/core/management/__init__.py", line 331, in execute_from_command_line utility.execute() File "/Users/danielroseman/Projects/django/django/core/management/__init__.py", line 323, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/danielroseman/Projects/django/django/core/management/base.py", line 350, in run_from_argv self.execute(*args, **cmd_options) File "/Users/danielroseman/Projects/django/django/core/management/base.py", line 401, in execute output = self.handle(*args, **options) File "/Users/danielroseman/Projects/django/django/core/management/commands/migrate.py", line 195, in handle executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) File "/Users/danielroseman/Projects/django/django/db/migrations/executor.py", line 110, in migrate self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial) File "/Users/danielroseman/Projects/django/django/db/migrations/executor.py", line 148, in apply_migration state = migration.apply(state, schema_editor) File "/Users/danielroseman/Projects/django/django/db/migrations/migration.py", line 116, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "/Users/danielroseman/Projects/django/django/db/migrations/operations/fields.py", line 201, in database_forwards schema_editor.alter_field(from_model, from_field, to_field) File "/Users/danielroseman/Projects/django/django/db/backends/base/schema.py", line 482, in alter_field old_db_params, new_db_params, strict) File "/Users/danielroseman/Projects/django/django/db/backends/base/schema.py", line 654, in _alter_field params, File "/Users/danielroseman/Projects/django/django/db/backends/base/schema.py", line 110, in execute cursor.execute(sql, params) File "/Users/danielroseman/Projects/django/django/db/backends/utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/Users/danielroseman/Projects/django/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/Users/danielroseman/Projects/django/django/db/utils.py", line 95, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/Users/danielroseman/Projects/django/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) django.db.utils.OperationalError: cannot ALTER TABLE "null_to_blank_model2" because it has pending trigger events }}} -- Ticket URL: <https://code.djangoproject.com/ticket/25105#comment:3> 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/065.c94cad9fc4e755a9c906f336486e8abc%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.