DigitalDisaster DigitalDisaster - 1 year ago 105
Python Question

Python format value is returning as null

Traceback (most recent call last):
File "", line 141, in <module>
cursor.execute("INSERT INTO accountsevents (accounts_id, events_id, date_created) VALUES ({0},{1}, TIMEZONE('utc', CURRENT_TIMESTAMP));".format(work, eventid))
psycopg2.IntegrityError: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, 2016-10-30 21:14:36.192339, 2016-10-30 21:14:36.192339, 1, 2, f, f, null).

I have a simulator dumping info directly into a database. Above the traceback you'll see the number
. That is a
of the value of
, which is a variable in the format method. For some reason it appears as null in the SQL expression. I'm racking my brain trying to understand what's going on here. this is on a remote VPS, but the same simulator file is working fine for me locally.

Any ideas?

Answer Source

I'll need more information to be sure, but the error says that the null value violates a not-null constraint in column id, but you're inserting the value of work into the accounts_id column.

You need to supply a value for the id column.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download