Opened 8 years ago
Last modified 8 years ago
#27311 closed New feature
Assigning ForeignKey fields in migrations — at Version 1
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): Payment = apps.get_model('finance', 'Payment') Invoice = apps.get_model('finance', 'Invoice') User = apps.get_model('accounts', 'User') payment = Payment.objects.last() invoice = Invoice( client=payment.user), status=5 ) invoice.save()
Also tried
invoice = Invoice( client=User.objects.get(pk=payment.user.pk), status=5 )
In both cases I get the error:
Cannot assign "<User: Some Client>": "Invoice.client" must be a "User" instance.
Note:
See TracTickets
for help on using tickets.