mpope9 / nba-sql

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

Error when starting MySQL server #77

Open sscrewston opened 2 years ago

sscrewston commented 2 years ago
Traceback (most recent call last):
  File "peewee.py", line 3144, in execute_sql
sqlite3.IntegrityError: UNIQUE constraint failed: team.team_id

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "nba_sql.py", line 389, in <module>
  File "gooey\python_bindings\gooey_decorator.py", line 134, in <lambda>
  File "nba_sql.py", line 128, in main
  File "general_requester.py", line 51, in populate
  File "db_utils.py", line 16, in insert_many
  File "db_utils.py", line 30, in __insert_many_sqlite
  File "peewee.py", line 1907, in inner
  File "peewee.py", line 1978, in execute
  File "peewee.py", line 2745, in _execute
  File "peewee.py", line 2474, in _execute
  File "peewee.py", line 3157, in execute
  File "peewee.py", line 3151, in execute_sql
  File "peewee.py", line 2917, in __exit__
  File "peewee.py", line 190, in reraise
  File "peewee.py", line 3144, in execute_sql
peewee.IntegrityError: UNIQUE constraint failed: team.team_id
mpope9 commented 2 years ago

What is the reproduction on this? Is this from running a fresh database or inserting into an existing one?

sscrewston commented 2 years ago

This is from running a fresh database from the Windows .exe file.

sscrewston commented 2 years ago

Also, unrelated question, I'm new to data so this may be a dumb question but why are there different game_ids for duplicate dates? For example, in the game table, there are 3 2021-10-19T00:00:00 entries and each has a different game_id despite being the same date.

I was just hoping you could explain this to me, I'm still trying to grasp relational databases.

mpope9 commented 2 years ago

Ok, will take a look at this when I get some free time.

As for multiple game_ids on the same date: multiple games can be played on the same day. It isn't a one-a-day scenario. Not a dumb question at all.

sscrewston commented 2 years ago

Ahhhh hearing that makes sense now. I understand, thank you for the clarification.

mpope9 commented 2 years ago

OK, so the Windows .exe is pretty old and a bugfix was merged that (I think) fixes this. This script can be used to create a release off the main branch, but I'll see if I can get a new .exe created by tomorrow. In the meantime you can try running the program from the commandline.

mpope9 commented 2 years ago

Also, what seasons were you loading?

sscrewston commented 2 years ago

Running a fresh one with the executable file. I’m using 2021-2022 season. I was able to get it to work with SQLite but I had trouble using the MySQL option.

On Tue, Aug 16, 2022 at 9:48 AM Matthew Pope @.***> wrote:

What is the reproduction on this? Is this from running a fresh database or inserting into an existing one?

— Reply to this email directly, view it on GitHub https://github.com/mpope9/nba-sql/issues/77#issuecomment-1216743478, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZFVOKDRURAGL4E4BM74RDTVZOS5FANCNFSM56TW5N2Q . You are receiving this because you authored the thread.Message ID: @.***>

sscrewston commented 2 years ago

I was loading 2021-2022

On Mon, Sep 5, 2022 at 5:47 PM Matthew Pope @.***> wrote:

Also, what seasons were you loading?

— Reply to this email directly, view it on GitHub https://github.com/mpope9/nba-sql/issues/77#issuecomment-1237510124, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZFVOKFG6WFR7RLSTHG3DS3V4Z2ABANCNFSM56TW5N2Q . You are receiving this because you authored the thread.Message ID: @.***>

mpope9 commented 2 years ago

I'll test this with MySQL.

alexboden commented 5 months ago

It fails when downloading multiple seasons individually:

nba-encyclopedia) *[main][~/docs/projects/nba-encyclopedia]$ gh repo clone mpope9/nba-sql
Cloning into 'nba-sql'...
remote: Enumerating objects: 20044, done.
remote: Counting objects: 100% (624/624), done.
remote: Compressing objects: 100% (232/232), done.
remote: Total 20044 (delta 427), reused 518 (delta 383), pack-reused 19420
Receiving objects: 100% (20044/20044), 141.82 MiB | 44.64 MiB/s, done.
Resolving deltas: 100% (2742/2742), done.
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0
Unpacking objects: 100% (1/1), 635 bytes | 317.00 KiB/s, done.
From https://github.com/Jman4190/nba-sql
 * [new branch]        master     -> upstream/master
! Repository Jman4190/nba-sql set as the default repository. To learn more about the default repository, run: gh repo set-default --help
(nba-encyclopedia) *[main][~/docs/projects/nba-encyclopedia]$ python stats/nba_sql.py --create-schema --database sqlite --skip-tables play_by_play pgtt shot_chart_detail --seasons '2022-23' --default-mode
python: can't open file '/Users/boden/docs/projects/nba-encyclopedia/stats/nba_sql.py': [Errno 2] No such file or directory
(nba-encyclopedia) *[main][~/docs/projects/nba-encyclopedia]$ cd nba-sql 
(nba-encyclopedia) [master][~/docs/projects/nba-encyclopedia/nba-sql]$ python stats/nba_sql.py --create-schema --database sqlite --skip-tables play_by_play pgtt shot_chart_detail --seasons '2022-23' --default-mode
Loading seasons: ['2022-23'].
Initializing sqlite database.
Loading the database in the default mode.
Initializing schema.
Populating team table.
team Table Loading |██████████████████████████████| 100.0% 
Loading event types.
Populating player data
player Table Loading |██████████████████████████████| 100.0% 
Loading player_game_log season Data |██████████████████████████████| 100.0% This one will take a while...
Loading cached game table.
Starting PlayerGameLog Insert
Finished PlayerGameLog Insert
Loading Seasonal Data |██████████████████████████████| 100.0% This one will take a while...
Done! Enjoy the hot, fresh database.
(nba-encyclopedia) *[master][~/docs/projects/nba-encyclopedia/nba-sql]$ python stats/nba_sql.py --create-schema --database sqlite --skip-tables play_by_play pgtt shot_chart_detail --seasons '2021-22' --default-mode
Loading seasons: ['2021-22'].
Initializing sqlite database.
Loading the database in the default mode.
Initializing schema.
Populating team table.
team Table Loading |██████████████████████████████| 100.0% 
Traceback (most recent call last):
  File "/Users/boden/anaconda3/envs/nba-encyclopedia/lib/python3.12/site-packages/peewee.py", line 3252, in execute_sql
    cursor.execute(sql, params or ())
sqlite3.IntegrityError: UNIQUE constraint failed: team.team_id

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/boden/docs/projects/nba-encyclopedia/nba-sql/stats/nba_sql.py", line 398, in <module>
    main(args, False)
  File "/Users/boden/docs/projects/nba-encyclopedia/nba-sql/stats/nba_sql.py", line 333, in main
    default_mode(settings, create_schema, request_gap, seasons, skip_tables, quiet or from_gui)
  File "/Users/boden/docs/projects/nba-encyclopedia/nba-sql/stats/nba_sql.py", line 109, in default_mode
    team_requester.populate()
  File "/Users/boden/docs/projects/nba-encyclopedia/nba-sql/stats/general_requester.py", line 51, in populate
    insert_many(self.settings, self.table, self.rows)
  File "/Users/boden/docs/projects/nba-encyclopedia/nba-sql/stats/db_utils.py", line 32, in insert_many
    __insert_many_sqlite(settings, table, rows)
  File "/Users/boden/docs/projects/nba-encyclopedia/nba-sql/stats/db_utils.py", line 47, in __insert_many_sqlite
    table.insert_many(row).execute()
  File "/Users/boden/anaconda3/envs/nba-encyclopedia/lib/python3.12/site-packages/peewee.py", line 1972, in inner
    return method(self, database, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/boden/anaconda3/envs/nba-encyclopedia/lib/python3.12/site-packages/peewee.py", line 2043, in execute
    return self._execute(database)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/boden/anaconda3/envs/nba-encyclopedia/lib/python3.12/site-packages/peewee.py", line 2848, in _execute
    return super(Insert, self)._execute(database)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/boden/anaconda3/envs/nba-encyclopedia/lib/python3.12/site-packages/peewee.py", line 2561, in _execute
    cursor = database.execute(self)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/boden/anaconda3/envs/nba-encyclopedia/lib/python3.12/site-packages/peewee.py", line 3260, in execute
    return self.execute_sql(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/boden/anaconda3/envs/nba-encyclopedia/lib/python3.12/site-packages/peewee.py", line 3250, in execute_sql
    with __exception_wrapper__:
  File "/Users/boden/anaconda3/envs/nba-encyclopedia/lib/python3.12/site-packages/peewee.py", line 3020, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "/Users/boden/anaconda3/envs/nba-encyclopedia/lib/python3.12/site-packages/peewee.py", line 192, in reraise
    raise value.with_traceback(tb)
  File "/Users/boden/anaconda3/envs/nba-encyclopedia/lib/python3.12/site-packages/peewee.py", line 3252, in execute_sql
    cursor.execute(sql, params or ())
peewee.IntegrityError: UNIQUE constraint failed: team.team_id
(nba-encyclopedia) *[master][~/docs/projects/nba-encyclopedia/nba-sql]$ 

But you can get around it like this:

(nba-encyclopedia) [master][~/docs/projects/nba-encyclopedia/nba-sql]$ python stats/nba_sql.py --create-schema --database sqlite --skip-tables play_by_play pgtt shot_chart_detail --seasons {'2021-22','2022-23'} --default-mode
Loading seasons: ['2021-22', '2022-23'].
Initializing sqlite database.
Loading the database in the default mode.
Initializing schema.
Populating team table.
team Table Loading |██████████████████████████████| 100.0% 
Loading event types.
Populating player data
player Table Loading |██████████████████████████████| 100.0% 
Loading player_game_log season Data |██████████████████████████████| 100.0% This one will take a while...
Loading cached game table.
Starting PlayerGameLog Insert
Finished PlayerGameLog Insert
Loading Seasonal Data |██████████████████████████████| 100.0% This one will take a while...
Done! Enjoy the hot, fresh database.