DSsenegal / saleor

BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

error while doing migrations #17

Open mass-gueye opened 1 month ago

mass-gueye commented 1 month ago

Titre : Problème de Migration avec django-tenant-schemas : Table Client Non Créée

Description :

Je rencontre un problème avec django-tenant-schemas dans une configuration de base Saleor. La table Client, censée être créée dans le schéma du locataire, n'est pas créée lors des migrations. De plus, je fais face à une ValueError liée aux routeurs de base de données lors de l'application des migrations.

Étapes pour Reproduire :

  1. Exécutez les migrations :

    python3 manage.py makemigrations
    python3 manage.py migrate_schemas --shared
  2. Observez la sortie : La sortie indique que le modèle Client est défini mais pas correctement créé dans la base de données. Lors de la migration, l'erreur suivante se produit :

    ValueError: Cannot assign "<Menu: Menu object (1)>": the current database router prevents this relation.

Error Logs :

/home/msg564/DSsenegal/saleor/settings.py:246: UserWarning: SECRET_KEY not configured, using a random temporary key.
2024-08-08 06:06:25,423 WARNING saleor.core.jwt_manager RSA_PRIVATE_KEY is missing. Using temporary key for local development with DEBUG mode. [PID:32431:MainThread]
Migrations for 'tenant':
  tenant/migrations/0001_initial.py
    - Create model Client

[standard:public] === Running migrate for schema public
...
[standard:public]   Applying site.0013_assign_default_menus...
Traceback (most recent call last):
  File "/home/msg564/DSsenegal/saleor/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/tenant_schemas/management/commands/migrate_schemas.py", line 33, in handle
    executor.run_migrations(tenants=[self.schema_name])
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/tenant_schemas/migration_executors/base.py", line 58, in run_migrations
    run_migrations(self.args, self.options, self.codename, public_schema_name)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/tenant_schemas/migration_executors/base.py", line 31, in run_migrations
    MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, **options)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 244, in handle
    post_migrate_state = executor.migrate(
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/db/migrations/migration.py", line 126, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/db/migrations/operations/special.py", line 190, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/home/msg564/DSsenegal/saleor/saleor/site/migrations/0013_assign_default_menus.py", line 16, in assign_default_menus
    site_settings.top_menu = top_menu
  File "/home/msg564/DSsenegal/saleor/venv/lib/python3.9/site-packages/django/db/models/fields/related_descriptors.py", line 229, in __set__
    raise ValueError('Cannot assign "%r": the current database router prevents this relation.' % value)
ValueError: Cannot assign "<Menu: Menu object (1)>": the current database router prevents this relation.
dofbi commented 1 month ago

Hello @mass-gueye Du nouveau ❓️

mass-gueye commented 1 month ago

Hello @dofbi non toujours le meme soucis. Je suis toujours des pistes

dofbi commented 1 month ago

Hello @mass-gueye Django Tenant avec une base pas vide ne facile pas la chose surtout pour les shared apps. Comme indiqué Capture d’écran du 2024-08-11 22-03-19

mass-gueye commented 1 month ago

Hello meme avec une base vide c'est pareil la migration commence et échoue à un certain point

mass-gueye commented 1 month ago

Titre : Erreur de migration avec l'intégration de django-tenant-schemas : relation "site_sitesettings" does not exist

Description :

Après avoir appliqué les migrations avec python manage.py migrate_schemas --shared, les migrations ont été appliquées avec succès. Cependant, lors de la création d'un nouveau locataire en utilisant python manage.py client, une erreur est survenue pendant la migration des schémas des locataires.

Message d'Erreur :

psycopg2.errors.UndefinedTable: relation "site_sitesettings" does not exist
LINE 1: ..._menu_id", "site_sitesettings"."top_menu_id" FROM "site_site...

Journal Détaillé :

Le message d'erreur suivant a été affiché lors de l'exécution de python manage.py client :

/home/msg564/DSsenegal/saleor/saleor/settings.py:246: UserWarning: SECRET_KEY not configured, using a random temporary key.
2024-08-13 00:07:28,182 WARNING saleor.core.jwt_manager RSA_PRIVATE_KEY is missing. Using temporary key for local development with DEBUG mode. [PID:36371:MainThread]
Tenant name: Tenantmaster
Paid until: 2025-08-12
Schema name: tenantmaster
On trial: False
[standard:tenantmaster] === Running migrate for schema tenantmaster
...
[standard:tenantmaster]   Applying site.0013_assign_default_menus...
Traceback (most recent call last):
  ...
  File "/home/msg564/DSsenegal/saleor/saleor/site/migrations/0013_assign_default_menus.py", line 14, in assign_default_menus
    site = Site.objects.get_current()
  ...
  django.db.utils.ProgrammingError: relation "site_sitesettings" does not exist

Étapes pour Reproduire :

  1. Appliquer les migrations avec python manage.py migrate_schemas --shared.
  2. Créer un nouveau locataire en utilisant python manage.py client.

Comportement Attendu :

La création du locataire et la migration des schémas devraient se terminer sans erreurs.

Comportement Actuel :

La migration de l'application site échoue avec une erreur indiquant que la table site_sitesettings n'existe pas.

Cause Possible :

Il semble que la table site_sitesettings soit attendue par l'une des migrations mais n'a pas été créée ou migrée correctement. Cela pourrait être dû à des migrations manquantes ou à un problème avec l'ordre des migrations.

Capture : image0

dofbi commented 1 month ago

Voire ici @mass-gueye

Image