Skip to content
Advertisement

ValueError: Field ‘id’ expected a number but got ‘Die erste Meldung’. after adding an item via console

I’m trying to add an item into db.sqlite3 via command line

JavaScript

but got this error:

JavaScript

Inside migrations001_initial.py below the field id of contentobject Meldung is declared as auto_created=True, but it seems it’s not working as expected.

How can I solve it?

  • expected result
    Field ‘id’ is generated automated by db.sqlite3

  • environment
    Python 3.8.2
    Django 3.1.3

  • models.py

JavaScript
  • migrations001_initial.py
JavaScript

Advertisement

Answer

The first parameter if you pass the value positionally (so without the name of the parameter), is id, so you assign 'Die erste Meldung' not to title but to the implicit id field.

You can solve this by passing it as a named parameter:

JavaScript

you can also pass None to the id parameter:

JavaScript

but it makes it unclear what each value represents in the Meldung object, as you found out yourself.

Advertisement