Opened 4 years ago

Last modified 12 months ago

#27339 assigned Cleanup/optimization

Adding an AutoField prompts for a default which creates a broken migration

Reported by: Tim Graham Owned by: za
Component: Migrations Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



class Foo(models.Model):
    id = models.CharField(max_length=20, primary_key=True)


class Foo(models.Model):
    character_id = models.AutoField(primary_key=True)

The created migration has these operations:

    field=models.AutoField(default=0, primary_key=True, serialize=False),

(entering 0 at the default prompt). Running the migration on PostgreSQL gives: ProgrammingError: multiple default values specified for column "character_id" of table "t27267_foo". I'm not sure if this can be made to work sensibly. Removing the default from the migration operation works, but if there's an existing data, the character_id field must be populated somehow (perhaps a RunPython could be done in the same migration?). #27338 is related. This was discovered while investigating #27267.

Change History (2)

comment:1 Changed 3 years ago by Akshay Raj Gollahalli

In Django 2.0b1 when trying to migrate without the default value, the CLI asks to enter a default value.

comment:2 Changed 12 months ago by za

Owner: changed from nobody to za
Status: newassigned

I am facing the same issue, but on my case I don't have data on the existing table. I'll think how to solve this issue.

Note: See TracTickets for help on using tickets.
Back to Top