Opened 8 years ago
Closed 8 years ago
#28084 closed Bug (duplicate)
FieldDoesNotExist when running a migration that removes a deleted field from unique_together
Reported by: | Bas ten Berge | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
I'm running into an issue when performing this change to this model:
class TopicOwnerThoughtStatus(models.Model): ''' Registers topic owner stats ''' thought = models.ForeignKey(Thought, help_text='Associates the state to a thought', db_index=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='topicownerstatus_set', help_text='Associates this state to an user') topic = models.ForeignKey(Topic, help_text='Associates this state to a thought and topic') notified_at = models.DateTimeField(null=True, blank=True, help_text='Contains the timestamp the topicowner was notified') shown_at = models.DateTimeField(null=True, blank=True, help_text='Contains the timestamp the topicowner viewed the thoughts') finished_at = models.DateTimeField(null=True, blank=True, help_text='Contains the timestamp the topicowner marked the topic closed') class Meta: unique_together = ('thought', 'user', 'topic', ) ordering = ('thought', ) verbose_name_plural = 'Topic owner status'
Changing this model to:
class TopicOwnerThoughtStatus(models.Model): ''' Registers topic owner stats ''' thought = models.ForeignKey(Thought, help_text='Associates the state to a thought', db_index=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='topicownerstatus_set', help_text='Associates this state to an user') topic_selector = models.CharField(max_length=36, null=True, blank=True, help_text='Contains the topic selector') notified_at = models.DateTimeField(null=True, blank=True, help_text='Contains the timestamp the topicowner was notified') shown_at = models.DateTimeField(null=True, blank=True, help_text='Contains the timestamp the topicowner viewed the thoughts') finished_at = models.DateTimeField(null=True, blank=True, help_text='Contains the timestamp the topicowner marked the topic closed') class Meta: unique_together = ('thought', 'user', 'topic_selector', ) ordering = ('thought', ) verbose_name_plural = 'Topic owner status'
will allow me to create a migration, but I'm not able to run that migration:
(env-brownpapersession)bastb@bastb-vps:/var/www/brownpapersession/dev/brownpapersession$ python manage.py migrate Operations to perform: Apply all migrations: ..., topic Running migrations: Applying topic.0014_auto_20170417_0941...Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line utility.execute() File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv self.execute(*args, **cmd_options) File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute output = self.handle(*args, **options) File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle fake_initial=fake_initial, File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 115, in migrate state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial) File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration state = migration.apply(state, schema_editor) File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 129, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 536, in database_forwards getattr(new_model._meta, self.option_name, set()), File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 348, in alter_unique_together self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique) File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 371, in _delete_composed_index columns = [model._meta.get_field(field).column for field in fields] File "/var/www/brownpapersession/dev/env-brownpapersession/local/lib/python2.7/site-packages/django/db/models/options.py", line 619, in get_field raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name))
I'm able to run this migration when following a two-step approach:
- add the topic_selector field
- change the unique_together to read ('thought', 'user', 'thought_selector', )
- create and run the migration
- remove the topic field
- create and run the migration
I'd expect to run this in one migration, though.
Change History (1)
comment:1 by , 8 years ago
Component: | Uncategorized → Migrations |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Summary: | FieldDoesNotExist when running a migration on Django 1.11 → FieldDoesNotExist when running a migration that removes a deleted field from unique_together |
Note:
See TracTickets
for help on using tickets.
Looks like a duplicate of #26180.