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

Creates bad migration when using DEFAULT_AUTO_FIELD #483

Closed
spapas opened this issue Aug 29, 2022 · 0 comments
Closed

Creates bad migration when using DEFAULT_AUTO_FIELD #483

spapas opened this issue Aug 29, 2022 · 0 comments

Comments

@spapas
Copy link
Contributor

spapas commented Aug 29, 2022

Hello, I'm using the DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" setting in a project.

When I install django-sql-explorer and run make migrations it will create a bad migration file on the django-sql-explorer instalaltion directory that alters the id fields. It's contents are similar to this:

# Generated by Django 4.1 on 2022-08-29 08:44

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("explorer", "0010_sql_required"),
    ]

    operations = [
        migrations.AlterField(
            model_name="query",
            name="id",
            field=models.BigAutoField(
                auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
            ),
        ),
        migrations.AlterField(
            model_name="querylog",
            name="id",
            field=models.BigAutoField(
                auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
            ),
        ),
    ]


To fix that we need to add the line default_auto_field = django.db.models.AutoField on apps.py so as to not use the django.db.models.BigAutoField I'm using on my settings. See https://docs.djangoproject.com/en/4.1/ref/applications/#django.apps.AppConfig.default_auto_field for reference.

This is a single line change, I'd be happy to provide a PR if needed.

BR,
Serafeim

marksweb pushed a commit that referenced this issue Aug 29, 2022
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

No branches or pull requests

2 participants