Skip to content

Creates bad migration when using DEFAULT_AUTO_FIELD #483

@spapas

Description

@spapas

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions