I want to add some data to the database with pandas .to_sql command. Is there a way I can get the auto-generated primary-key of the inserted objects as I need it for creating foreign keys?
So far I did this:
Models:
from django.db import models
class Vertices(models.Model):
x = models.FloatField()
y = models.FloatField()
z = models.FloatField()
class Face(models.Model):
Points = models.ForeignKey(Vertices, on_delete=models.PROTECT,)
add points to db:
points.to_sql(Vertices._meta.db_table.lower(), con=engine, if_exists='append', index=False)
now I want to create a foreign key in the Face table to these points:
Face.objects.create(Points_id= ...)
Thank you very much!