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/init.py”, 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/manage.py”, line 23, in
main()
File “/Users/matthewmoore/Desktop/optimizer_v2/manage.py”, line 19, in main
execute_from_command_line(sys.argv)
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/core/management/init.py”, line 442, in execute_from_command_line
utility.execute()
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/core/management/init.py”, line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/core/management/base.py”, 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/base.py”, 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/base.py”, 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/migrate.py”, 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/executor.py”, 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/executor.py”, 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/executor.py”, 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/migration.py”, line 132, in apply
operation.database_forwards(
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/migrations/operations/fields.py”, line 108, in database_forwards
schema_editor.add_field(
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/backends/sqlite3/schema.py”, 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/schema.py”, line 238, in _remake_table
self.effective_default(create_field),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/matthewmoore/.local/share/virtualenvs/optimizer_v2-VTEds7qS/lib/python3.11/site-packages/django/db/backends/base/schema.py”, 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/related.py”, 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/init.py”, 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/init.py”, 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/init.py”, 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
INSTALLED_APPS = [
‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
‘golf’
]
I can’t really think of much else … as I have barely changed anything! driving me nuts haha