Opened 9 years ago
Last modified 9 years ago
#27311 closed New feature
Assigning ForeignKey fields in migrations — at Version 3
| Reported by: | Odero | Owned by: | nobody |
|---|---|---|---|
| Component: | Migrations | Version: | dev |
| Severity: | Normal | Keywords: | migrations, foreignkey, cache |
| Cc: | Markus Holtermann | Triage Stage: | Someday/Maybe |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Trying to create the migration below which is failing. It seems like the same issue discussed and resolved in #24282.
def generate_invoices(apps, schema_editor):
A = apps.get_model('app1', 'A')
B = apps.get_model('app1', 'B')
User = apps.get_model('accounts', 'User')
a = A.objects.last()
b = B(
client=a.user,
status=5
)
b.save()
Also tried
b = B(
client=User.objects.get(pk=a.user.pk),
status=5
)
In both cases I get the error:
Cannot assign "<User: Some User>": "B.client" must be a "User" instance.
Change History (3)
comment:1 by , 9 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 9 years ago
| Description: | modified (diff) |
|---|
comment:3 by , 9 years ago
| Component: | Uncategorized → Migrations |
|---|---|
| Description: | modified (diff) |
Note:
See TracTickets
for help on using tickets.
I can't reproduce this. Could you provide a sample project and confirm your Django version?