#22435 closed Bug (fixed)
Adding a ManyToManyField and running makemigrations prompts for a default
Reported by: | andrewsg | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | gabrielbrasil, Sebastian Bauer | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Adding a ManyToManyField to an existing model prompts the user as so:
You are trying to add a non-nullable field 'authors' to post without a default; we can't do that (the database needs something to populate existing rows). Please select a fix: 1) Provide a one-off default now (will be set on all existing rows) 2) Quit, and let me add a default in models.py Select an option:
Since there is no way to specify a default for an M2M field in the interactive process, this makes it impossible to add M2M fields.
The workaround is to cancel and add null=True
to the field definition. But null=True
does not apply to ManyToManyField
, so this should be unnecessary.
Change History (7)
comment:1 by , 11 years ago
Component: | Uncategorized → Migrations |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 11 years ago
I can reproduce this too. What about forcing ManyToManyField to always be null=True?
https://github.com/django/django/pull/2563/files
That's how it behaves normally anyway, right?
comment:3 by , 11 years ago
Cc: | added |
---|
comment:4 by , 11 years ago
Cc: | added |
---|
comment:5 by , 11 years ago
Has patch: | set |
---|---|
Severity: | Normal → Release blocker |
I didn't see a way to do this without special casing M2M: PR.
comment:6 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Could reproduce using master.
I'm unsure how we should solve this. It would be great if we could avoid special casing
ManyToManyField
here.