mpope9 / nba-sql

:basketball: An application to build an NBA database backed by MySQL, Postgres, or SQLite
Apache License 2.0
171 stars 20 forks source link

Error when creating Team table results in empty Game table #87

Open asubbarao opened 1 year ago

asubbarao commented 1 year ago

I downloaded postgres.app for mac, ran the initialize script. Then I run:

python3 stats/nba_sql.py --create-schema --database postgres --skip-tables play_by_play pgtt

and get the result:

Loading seasons: ['2023-24'].
Connecting to postgres database.

But I notice most tables are empty. The above produced no other errors. So I tried using the GUI option, and received this error:

Loading seasons: ['2023-24'].
Connecting to postgres database.
Loading the database in the default mode.
Initializing schema.
Populating team table.

team Table Loading |------------------------------| 0.0% 

team Table Loading |█-----------------------------| 3.3% 

team Table Loading |██----------------------------| 6.7% 

team Table Loading |███---------------------------| 10.0% 

team Table Loading |████--------------------------| 13.3% 

team Table Loading |█████-------------------------| 16.7% 

team Table Loading |██████------------------------| 20.0% 

team Table Loading |███████-----------------------| 23.3% 

team Table Loading |████████----------------------| 26.7% 

team Table Loading |█████████---------------------| 30.0% 

team Table Loading |██████████--------------------| 33.3% 

team Table Loading |███████████-------------------| 36.7% 

team Table Loading |████████████------------------| 40.0% 

team Table Loading |█████████████-----------------| 43.3% 

team Table Loading |██████████████----------------| 46.7% 

team Table Loading |███████████████---------------| 50.0% 

team Table Loading |████████████████--------------| 53.3% 

team Table Loading |█████████████████-------------| 56.7% 

team Table Loading |██████████████████------------| 60.0% 

team Table Loading |███████████████████-----------| 63.3% 

team Table Loading |████████████████████----------| 66.7% 

team Table Loading |█████████████████████---------| 70.0% 

team Table Loading |██████████████████████--------| 73.3% 

team Table Loading |███████████████████████-------| 76.7% 

team Table Loading |████████████████████████------| 80.0% 

team Table Loading |█████████████████████████-----| 83.3% 

team Table Loading |██████████████████████████----| 86.7% 

team Table Loading |███████████████████████████---| 90.0% 

team Table Loading |████████████████████████████--| 93.3% 

team Table Loading |█████████████████████████████-| 96.7% 

team Table Loading |██████████████████████████████| 100.0% 

Traceback (most recent call last):
  File "peewee.py", line 3160, in execute_sql
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "team_pkey"
DETAIL:  Key (team_id)=(1610612737) already exists.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "gui.py", line 103, in <module>
  File "gooey/python_bindings/gooey_decorator.py", line 134, in <lambda>
  File "gui.py", line 99, in gui_main
  File "nba_sql.py", line 291, in main
  File "nba_sql.py", line 86, in default_mode
  File "general_requester.py", line 51, in populate
  File "db_utils.py", line 20, in insert_many
  File "peewee.py", line 1911, in inner
  File "peewee.py", line 1982, in execute
  File "peewee.py", line 2761, in _execute
  File "peewee.py", line 2477, in _execute
  File "peewee.py", line 2484, in execute_returning
  File "peewee.py", line 3173, in execute
  File "peewee.py", line 3167, in execute_sql
  File "peewee.py", line 2933, in __exit__
  File "peewee.py", line 191, in reraise
  File "peewee.py", line 3160, in execute_sql
peewee.IntegrityError: duplicate key value violates unique constraint "team_pkey"
DETAIL:  Key (team_id)=(1610612737) already exists.

[82546] Failed to execute script 'gui' due to unhandled exception: duplicate key value violates unique constraint "team_pkey"
DETAIL:  Key (team_id)=(1610612737) already exists.

[82546] Traceback:
Traceback (most recent call last):
  File "peewee.py", line 3160, in execute_sql
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "team_pkey"
DETAIL:  Key (team_id)=(1610612737) already exists.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "gui.py", line 103, in <module>
  File "gooey/python_bindings/gooey_decorator.py", line 134, in <lambda>
  File "gui.py", line 99, in gui_main
  File "nba_sql.py", line 291, in main
  File "nba_sql.py", line 86, in default_mode
  File "general_requester.py", line 51, in populate
  File "db_utils.py", line 20, in insert_many
  File "peewee.py", line 1911, in inner
  File "peewee.py", line 1982, in execute
  File "peewee.py", line 2761, in _execute
  File "peewee.py", line 2477, in _execute
  File "peewee.py", line 2484, in execute_returning
  File "peewee.py", line 3173, in execute
  File "peewee.py", line 3167, in execute_sql
  File "peewee.py", line 2933, in __exit__
  File "peewee.py", line 191, in reraise
  File "peewee.py", line 3160, in execute_sql
peewee.IntegrityError: duplicate key value violates unique constraint "team_pkey"
DETAIL:  Key (team_id)=(1610612737) already exists.
mpope9 commented 1 year ago

Hi, thank you for the report. Two things:

  1. Looks like there is a bug and this switches to the next season too early. I'm not too sure how to actually fix this.
  2. Try this to pull from the 'actual' current season.
    python3 stats/nba_sql.py --default-mode --seasons 2022-23 --create-schema --database="postgres" --skip-tables play_by_play pgtt

First, I'd suggest you start with a fresh database. See the scripts/drop.sql for what to run.

mpope9 commented 1 year ago

I will try to add a few things:

  1. Fix the current season.
  2. Make a better error message when neither --default-mode or --current-season-mode is selected.
  3. Error if --current-season-mode is used when the database is not initialized.