cli/db: handle integer foreign keys being null
This commit is contained in:
parent
fcad77a839
commit
6f9cd1eaaa
1 changed files with 6 additions and 1 deletions
|
@ -43,12 +43,17 @@ def impot(model: db.Model):
|
|||
x = model()
|
||||
for i in range(len(header)):
|
||||
if header[i] in ["added", "updated", "destroyed", "deprecated", "last_updated", "terraform_updated"]:
|
||||
# datetime fields
|
||||
if line[i] == "":
|
||||
line[i] = None
|
||||
else:
|
||||
line[i] = datetime.datetime.strptime(line[i], "%Y-%m-%d %H:%M:%S.%f")
|
||||
if header[i] in ["eotk"]:
|
||||
elif header[i] in ["eotk"]:
|
||||
# boolean fields
|
||||
line[i] = line[i] == "True"
|
||||
elif header[i].endswith("_id") and line[i] == "":
|
||||
# integer foreign keys
|
||||
line[i] = None
|
||||
setattr(x, header[i], line[i])
|
||||
db.session.add(x)
|
||||
db.session.commit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue