Opened 8 years ago
Last modified 8 years ago
#27311 closed New feature
Assigning ForeignKey fields in migrations — at Version 2
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 here https://code.djangoproject.com/ticket/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 ) invoice.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 (2)
comment:1 by , 8 years ago
Description: | modified (diff) |
---|
comment:2 by , 8 years ago
Description: | modified (diff) |
---|
Note:
See TracTickets
for help on using tickets.