Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makemigrations in project tries to drop and re-create indexes #222

Closed
intgr opened this issue Jul 19, 2021 · 9 comments · Fixed by #283
Closed

makemigrations in project tries to drop and re-create indexes #222

intgr opened this issue Jul 19, 2021 · 9 comments · Fixed by #283

Comments

@intgr
Copy link
Contributor

intgr commented Jul 19, 2021

With dango-celery-results 2.1.0 or 2.2.0, if I run makemigrations in my project, Django now thinks there are unmigrated changes in django_celery_results. And it actually creates a new migration file under the site-packages directory. :(

However, if I run makemigrations in django-celery-results project, no migration changes are detected. I'm not yet sure how my project differs. Both are using Python 3.9 and Django 3.2.5. I will update if I figure it out.

(I split this issue out from #208 (comment))

The output differs slightly with versions.

Result with 2.2.0:

% ./manage.py makemigrations 
Migrations for 'django_celery_results':
  .../lib/python3.9/site-packages/django_celery_results/migrations/0011_auto_20210719_0953.py
    - Remove index django_cele_date_cr_bd6c1d_idx from groupresult
    - Remove index django_cele_date_do_caae0e_idx from groupresult
    - Remove index django_cele_task_na_08aec9_idx from taskresult
    - Remove index django_cele_status_9b6201_idx from taskresult
    - Remove index django_cele_worker_d54dd8_idx from taskresult
    - Remove index django_cele_date_cr_f04a50_idx from taskresult
    - Remove index django_cele_date_do_f59aad_idx from taskresult
    - Create index django_cele_date_cr_0d69cb_idx on field(s) date_created of model groupresult
    - Create index django_cele_date_do_030540_idx on field(s) date_done of model groupresult
    - Create index django_cele_task_na_4bcd60_idx on field(s) task_name of model taskresult
    - Create index django_cele_status_9c2623_idx on field(s) status of model taskresult
    - Create index django_cele_worker_d87a3d_idx on field(s) worker of model taskresult
    - Create index django_cele_date_cr_2b7193_idx on field(s) date_created of model taskresult
    - Create index django_cele_date_do_c4aa5e_idx on field(s) date_done of model taskresult

Result with 2.1.0:

% ./manage.py makemigrations django_celery_results
Migrations for 'django_celery_results':
  .../lib/python3.9/site-packages/django_celery_results/migrations/0010_auto_20210719_1025.py
    - Remove index django_cele_group_i_299b0d_idx from chordcounter
    - Remove index django_cele_group_i_3cddec_idx from groupresult
    - Remove index django_cele_date_cr_bd6c1d_idx from groupresult
    - Remove index django_cele_date_do_caae0e_idx from groupresult
    - Remove index django_cele_task_id_7f8fca_idx from taskresult
    - Remove index django_cele_task_na_08aec9_idx from taskresult
    - Remove index django_cele_status_9b6201_idx from taskresult
    - Remove index django_cele_worker_d54dd8_idx from taskresult
    - Remove index django_cele_date_cr_f04a50_idx from taskresult
    - Remove index django_cele_date_do_f59aad_idx from taskresult
    - Alter field group_id on chordcounter
    - Alter field group_id on groupresult
    - Alter field task_id on taskresult
    - Create index django_cele_group_i_853755_idx on field(s) group_id of model chordcounter
    - Create index django_cele_group_i_99a2b7_idx on field(s) group_id of model groupresult
    - Create index django_cele_date_cr_0d69cb_idx on field(s) date_created of model groupresult
    - Create index django_cele_date_do_030540_idx on field(s) date_done of model groupresult
    - Create index django_cele_task_id_c21066_idx on field(s) task_id of model taskresult
    - Create index django_cele_task_na_4bcd60_idx on field(s) task_name of model taskresult
    - Create index django_cele_status_9c2623_idx on field(s) status of model taskresult
    - Create index django_cele_worker_d87a3d_idx on field(s) worker of model taskresult
    - Create index django_cele_date_cr_2b7193_idx on field(s) date_created of model taskresult
    - Create index django_cele_date_do_c4aa5e_idx on field(s) date_done of model taskresult
@AllexVeldman
Copy link
Contributor

Hi @intgr,
There were multiple issues in 2.1.0 migrations that 2.2.0 tried to solved
#210 #208 #206

I'm unable to reproduce your outcome, can you add the ./manage.py showmigrations django_celery_results output before and after upgrading?

@stiko
Copy link

stiko commented Sep 12, 2021

I had similar issue after upgrading to 2.2.0. It generated a new migration when I ran ./manage.py makemigraioin.
Solution:

  • Remove the generated migration.
  • Remove the django_celery_results tables.
  • Remove django_celery_results migrations from django_migrations table.
  • Run ./manage.py migrate.

Fixes the issue for me :)

@auvipy
Copy link
Member

auvipy commented Oct 11, 2021

i think trying from aster wont do this

@auvipy auvipy closed this as completed Oct 11, 2021
@erkib
Copy link

erkib commented Nov 25, 2021

Using Oracle backend, the suggestion by @stiko is not effective. I tried like this:

./manage.py migrate django_celery_results zero
./manage.py migrate

Result is the same:
AssertionError: Models have changes that are not yet reflected in migrations:
E django_celery_results:
E <RemoveIndex model_name='groupresult', name='django_cele_date_cr_bd6c1d_idx'>
E <RemoveIndex model_name='groupresult', name='django_cele_date_do_caae0e_idx'>
E <RemoveIndex model_name='taskresult', name='django_cele_task_na_08aec9_idx'>
E <RemoveIndex model_name='taskresult', name='django_cele_status_9b6201_idx'>
E <RemoveIndex model_name='taskresult', name='django_cele_worker_d54dd8_idx'>
E <RemoveIndex model_name='taskresult', name='django_cele_date_cr_f04a50_idx'>
E <RemoveIndex model_name='taskresult', name='django_cele_date_do_f59aad_idx'>
E <AddIndex model_name='groupresult', index=<Index: fields='date_created'>>
E <AddIndex model_name='groupresult', index=<Index: fields='date_done'>>
E <AddIndex model_name='taskresult', index=<Index: fields='task_name'>>
E <AddIndex model_name='taskresult', index=<Index: fields='status'>>
E <AddIndex model_name='taskresult', index=<Index: fields='worker'>>
E <AddIndex model_name='taskresult', index=<Index: fields='date_created'>>
E <AddIndex model_name='taskresult', index=<Index: fields='date_done'>>

@auvipy
Copy link
Member

auvipy commented Nov 25, 2021

v2.2.0...master can you check the commit log

@erkib
Copy link

erkib commented Nov 25, 2021

If you refer this commit 7c7cb67, then executing the same command as the test:

./manage.py makemigrations django_celery_results --check --dry-run

Migrations for 'django_celery_results':
../lib/python3.10/site-packages/django_celery_results/migrations/0011_auto_20211125_1132.py
- Remove index django_cele_date_cr_bd6c1d_idx from groupresult
- Remove index django_cele_date_do_caae0e_idx from groupresult
- Remove index django_cele_task_na_08aec9_idx from taskresult
- Remove index django_cele_status_9b6201_idx from taskresult
- Remove index django_cele_worker_d54dd8_idx from taskresult
- Remove index django_cele_date_cr_f04a50_idx from taskresult
- Remove index django_cele_date_do_f59aad_idx from taskresult
- Create index django_cele_date_cr_0d69cb_idx on field(s) date_created of model groupresult
- Create index django_cele_date_do_030540_idx on field(s) date_done of model groupresult
- Create index django_cele_task_na_4bcd60_idx on field(s) task_name of model taskresult
- Create index django_cele_status_9c2623_idx on field(s) status of model taskresult
- Create index django_cele_worker_d87a3d_idx on field(s) worker of model taskresult
- Create index django_cele_date_cr_2b7193_idx on field(s) date_created of model taskresult
- Create index django_cele_date_do_c4aa5e_idx on field(s) date_done of model taskresult

@erkib
Copy link

erkib commented Nov 25, 2021

Verified - this is related to Oracle driver.

@intgr
Copy link
Contributor Author

intgr commented Feb 1, 2022

This issue still occurs on django-celery-results master branch, but after investigating further, it looks like a Django bug. Index names are not stable between different database engines: https://code.djangoproject.com/ticket/33483

I will try to figure out whether there are any work-arounds that could be implemented.

Update: Opened pull request #283

intgr added a commit to intgr/django-celery-results that referenced this issue Feb 1, 2022
Fixes celery#222.

Django's auto-generated index names are not stable across database engines: https://code.djangoproject.com/ticket/33483

Added explicit index names to `models.py` to work around that, until a fix is implemented in Django itself.
@auvipy
Copy link
Member

auvipy commented Feb 2, 2022

thanks for the PR, I left reveiw comment

auvipy pushed a commit that referenced this issue Feb 9, 2022
Fixes #222.

Django's auto-generated index names are not stable across database engines: https://code.djangoproject.com/ticket/33483

Added explicit index names to `models.py` to work around that, until a fix is implemented in Django itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants