allegro / ralph

Ralph is the CMDB / Asset Management system for data center and back office hardware.
https://ralph.allegro.tech/
Apache License 2.0
2.24k stars 551 forks source link

Found wrong number (0) on migrate #3653

Open wid opened 3 years ago

wid commented 3 years ago

Steps to reproduce

Install ralph onto mysql 8.0.23

Expected behavior

ralph migrate work

Actual behavior

Sometime it works, sometime I get this:

  Applying data_importer.0004_auto_20160728_1046...Traceback (most recent call last):
  File "/opt/ralph/ralph-core/bin/ralph", line 8, in <module>
    sys.exit(prod())
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/ralph/__main__.py", line 28, in prod
    main('ralph.settings.prod')
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/ralph/__main__.py", line 14, in main
    execute_from_command_line(sys.argv)
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/migrations/executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/migrations/executor.py", line 148, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/migrations/migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/migrations/operations/models.py", line 359, in database_forwards
    getattr(new_model._meta, self.option_name, set()),
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 320, in alter_unique_together
    self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique)
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/backends/mysql/schema.py", line 80, in _delete_composed_index
    return super(DatabaseSchemaEditor, self)._delete_composed_index(model, fields, *args)
  File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 349, in _delete_composed_index
    ", ".join(columns),
ValueError: Found wrong number (0) of constraints for data_importer_importedobjects(content_type_id, object_pk, old_object_pk)

State of the database:

mysql> show create table data_importer_importedobjects \G 1. row Table: data_importer_importedobjects Create Table: CREATE TABLE data_importer_importedobjects ( id int NOT NULL AUTO_INCREMENT, created datetime(6) NOT NULL, modified datetime(6) NOT NULL, object_pk int NOT NULL, old_object_pk varchar(255) NOT NULL, content_type_id int NOT NULL, PRIMARY KEY (id), UNIQUE KEY data_importer_importedobje_content_type_id_1cc729b58d8480f0_uniq (content_type_id,object_pk,old_object_pk), KEY data_importer_importedobjects_120cc505 (object_pk), KEY data_importer_importedobjects_45b250e8 (old_object_pk), KEY data_importer_importedobjects_417f1b1c (content_type_id), CONSTRAINT data__content_type_id_2132ebbc23fb1882_fk_django_content_type_id FOREIGN KEY (content_type_id) REFERENCES django_content_type (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 1 row in set (0.00 sec)

Environment

I used my helm chart.

Dimonyga commented 11 months ago

Workaround ALTER TABLE data_importer_importedobjects ADD CONSTRAINT temp_fix UNIQUE (content_type_id, object_pk, old_object_pk); and run migrate ALTER TABLE data_importer_importedobjects drop CONSTRAINT temp_fix; and run migrate