wger-project / docker

Production...ish docker-compose image for wger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exercises Not syncing

deboy69 opened this issue · comments

After running.

docker-compose exec web python3 manage.py sync-exercises

*** Synchronizing categories...
done!

*** Synchronizing muscles...
done!

*** Synchronizing equipment...
done!

*** Synchronizing exercises...
Saved new exercise 2 Handed Kettlebell Swing
Traceback (most recent call last):
File "/home/wger/src/wger/exercises/management/commands/sync-exercises.py", line 104, in sync_exercises
exercise = Exercise.objects.get(uuid=exercise_uuid)
File "/usr/local/lib/python3.10/dist-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 435, in get
raise self.model.DoesNotExist(
wger.exercises.models.exercise.Exercise.DoesNotExist: Exercise matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.ForeignKeyViolation: insert or update on table "exercises_exercisebase" violates foreign key constraint "exercises_exercisebase_license_id_7d658f59_fk_core_license_id"
DETAIL: Key (license_id)=(2) is not present in table "core_license".

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/wger/src/manage.py", line 25, in
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/init.py", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.10/dist-packages/django/core/management/init.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/home/wger/src/wger/exercises/management/commands/sync-exercises.py", line 84, in handle
self.sync_exercises(headers, remote_url)
File "/home/wger/src/wger/exercises/management/commands/sync-exercises.py", line 125, in sync_exercises
base.save()
File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 739, in save
self.save_base(using=using, force_insert=force_insert,
File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 776, in save_base
updated = self._save_table(
File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 881, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 919, in _do_insert
return manager._insert(
File "/usr/local/lib/python3.10/dist-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 1270, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/usr/local/lib/python3.10/dist-packages/django/db/models/sql/compiler.py", line 1416, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 79, in _execute
with self.db.wrap_database_errors:
File "/usr/local/lib/python3.10/dist-packages/django/db/utils.py", line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: insert or update on table "exercises_exercisebase" violates foreign key constraint "exercises_exercisebase_license_id_7d658f59_fk_core_license_id"
DETAIL: Key (license_id)=(2) is not present in table "core_license".

mhhhh, why doesn't it find the license??? Can you load the default licenses with python manage.py loaddata licenses and try again?

On the other hand it's probably not a bad idea to sync them as well, even if they basically never change

No change with loaddata licenses

and still the same error with the license_id? 🧐

it appears that way

sudo docker-compose exec web python3 manage.py sync-exercises
*** Synchronizing categories...
done!

*** Synchronizing muscles...
done!

*** Synchronizing equipment...
done!

*** Synchronizing exercises...
Saved new exercise 2 Handed Kettlebell Swing
Traceback (most recent call last):
File "/home/wger/src/wger/exercises/management/commands/sync-exercises.py", line 104, in sync_exercises
exercise = Exercise.objects.get(uuid=exercise_uuid)
File "/usr/local/lib/python3.10/dist-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 435, in get
raise self.model.DoesNotExist(
wger.exercises.models.exercise.Exercise.DoesNotExist: Exercise matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.ForeignKeyViolation: insert or update on table "exercises_exercise" violates foreign key constraint "exercises_exercise_language_id_9675c687_fk_core_language_id"
DETAIL: Key (language_id)=(2) is not present in table "core_language".

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/wger/src/manage.py", line 25, in
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/init.py", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.10/dist-packages/django/core/management/init.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/home/wger/src/wger/exercises/management/commands/sync-exercises.py", line 84, in handle
self.sync_exercises(headers, remote_url)
File "/home/wger/src/wger/exercises/management/commands/sync-exercises.py", line 139, in sync_exercises
exercise.save()
File "/home/wger/src/wger/exercises/models/exercise.py", line 130, in save
super(Exercise, self).save(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 739, in save
self.save_base(using=using, force_insert=force_insert,
File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 776, in save_base
updated = self._save_table(
File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 881, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 919, in _do_insert
return manager._insert(
File "/usr/local/lib/python3.10/dist-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 1270, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/usr/local/lib/python3.10/dist-packages/django/db/models/sql/compiler.py", line 1416, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 79, in _execute
with self.db.wrap_database_errors:
File "/usr/local/lib/python3.10/dist-packages/django/db/utils.py", line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: insert or update on table "exercises_exercise" violates foreign key constraint "exercises_exercise_language_id_9675c687_fk_core_language_id"
DETAIL: Key (language_id)=(2) is not present in table "core_language".

at least now it's the language that's missing. I mean, we can now do python manage.py loaddata languages and try again till this goes through, but why are those tables now empty?

That appeared to work

I've opened a new issue for automatically syncronising the languages and licenses: wger-project/wger#1164

That would make sure that at least this specific case won't happen again, closing here (but I still can't understand why those entries were deleted in the first place)