1

I have a model:

class errors(models.Model):
    date           = models.DateTimeField()
    msg            = models.CharField(max_length=500)

I simply cannot get the date format right when inserting. I do

msg = "error" 
date = datetime.datetime.now()

cursor = connection.cursor()
cursor.execute("INSERT INTO cmt_errors('date', 'msg') VALUES (%s, %s)", (date, msg))

How should I format date so I don't get a syntax error? I am, btw, able to do a select so I've got the tables imported, etc.

1 Answer 1

1

Do not put single-quotes around the column names:

"INSERT INTO cmt_errors(date, msg) VALUES (%s, %s)"
Sign up to request clarification or add additional context in comments.

1 Comment

DOH! Thank-you! Solves my problem. I had been staring myself blind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.