Super frustrating error in just skeleton (so far) app ValueError: Field 'id' expected a number but got 'admin'.

Hi there,

So I am pretty new to programming. Have dabbled for 2-3 years but this is my first (attempted) big project.

Im legitimately right at the beginning of the project, there is barely any new logic in the project (I even tried to re-create the project from scratch to see if the error replicated in the new version, and it still does). I tried reading about 10 threads from the past with the same error, but in all cases it seems the problem was “non-obvious” and unique to the individual project.

Project is a simple fantasy golf lineup optimizer. Find the highest project lineup of 6 golfers using mixed-integer programming. But I am legitimately just beginning to write the logic …

I am defining my golfer model as

class Golfer(models.Model):
name=models.CharField(max_length=100, null=True)
name_id = models.CharField(max_length=100, null=True)
salary = models.IntegerField(null=True)
proj = models.DecimalField(max_digits=7, decimal_places=3, null=True)

and my lineup model:

class Lineup(models.Model):
proj = models.DecimalField(max_digits=5, decimal_places=3, null=True)
salary = models.IntegerField(null=True)
#thinking of storing as json for now, can revisit
players = models.CharField(max_length=1000, null=True)
#which user made this lineup/set of lineups
creator = models.ForeignKey(User, on_delete=models.CASCADE, related_name=“optimized_lineups”, default=1000, null=True)

The only reason I set my default value on “creator” to 1000, is because I had originally set it to “admin”, and that’s when this error started happening. It almost seems like this initial error that I made is persisting in the backend somehow … but im really not sure how or why that would be the case. And also to be clear, the error persists even if I delete the creator field, and even if I delete the Lineup model entirely. I just have no idea how this is happening because I have barely changed the Django skeleton at all. Here is the traceback: Apologies in advance if this is a very stupid error, I tried following the traceback all the way through but it ended up getting very murky honestly for my newish to programming brain.

Running migrations:
Applying golf.0002_golfer_opto_exclude_golfer_opto_like_lineup_creator_and_more…Traceback (most recent call last):
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/models/fields/”, line 2053, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: ‘admin’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/Users/matthewmoore/Desktop/optimizer_v2/”, line 23, in
File “/Users/matthewmoore/Desktop/optimizer_v2/”, line 19, in main
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/core/management/”, line 442, in execute_from_command_line
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/core/management/”, line 436, in execute
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/core/management/”, line 412, in run_from_argv
self.execute(*args, **cmd_options)
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/core/management/”, line 458, in execute
output = self.handle(*args, **options)
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/core/management/”, line 106, in wrapper
res = handle_func(*args, **kwargs)
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/core/management/commands/”, line 356, in handle
post_migrate_state = executor.migrate(
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/migrations/”, line 135, in migrate
state = self._migrate_all_forwards(
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/migrations/”, line 167, in _migrate_all_forwards
state = self.apply_migration(
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/migrations/”, line 252, in apply_migration
state = migration.apply(state, schema_editor)
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/migrations/”, line 132, in apply
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/migrations/operations/”, line 108, in database_forwards
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/backends/sqlite3/”, line 398, in add_field
self._remake_table(model, create_field=field)
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/backends/sqlite3/”, line 238, in _remake_table
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/backends/base/”, line 429, in effective_default
return field.get_db_prep_save(self._effective_default(field), self.connection)
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/models/fields/”, line 1129, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/models/fields/”, line 954, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/models/fields/”, line 2742, in get_db_prep_value
value = self.get_prep_value(value)
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/models/fields/”, line 2055, in get_prep_value
raise e.class(
ValueError: Field ‘id’ expected a number but got ‘admin’.

Some other things that might help:

Application definition


I can’t really think of much else … as I have barely changed anything! driving me nuts haha

Well … so the only place in my entire project I could find the string literal ‘admin’ was in one of my earlier migrations that erroneously set the default of “creator” (foreign key field) to ‘admin’.

I went and simply deleted everything in migrations/ (except for and tried migrating again. And it worked … idk seems like weird buggy logic to me somewhere in there. But for someone that has this issue in the future … seems the solution is to delete your past migration .py files in the migrations folder.

Congratulations on fixing your issue, and thanks for posting the solution back on the forum so others can find it.

In the future, please use “preformatted text“ blocks for your code examples. Without them, your post is quite hard to read.

1 Like