[Fixed]-Assign existing ForeignKey to model fields via command line/script using pk or other means

1👍

You code doesn’t make sense. You just did a creation on an aircraft by doing:

# you are creating an aircraft instance here
aircraft = Aircraft(aircraft_type = row_id)
# instance saved to database, all good so far
aircraft.save()
# why don't you return it?
return aircraft

Why don’t you just return that aircraft instance? Why do you create another aircraft instance(not saved):

# What are you trying to do here? This is an unsaved aircraft instance
aircraft = Aircraft(aircraft.pk)
return aircraft

Leave a comment