nfldb: Key (pos_team)=(JAX) is not present in table "team".
Getting the following from nfldb-update. TIA, PLA
/usr/local/bin/nfldb-update
-------------------------------------------------------------------------------
STARTING NFLDB UPDATE AT 2016-09-18 17:56:02.147214
Connecting to nfldb... done.
Setting timezone to UTC... done.
Locking write access to tables... done.
Updating season phase, year and week... done.
Bulk inserting data for 2 games...
Sending batch of data to database.
Traceback (most recent call last):
File "/usr/local/bin/nfldb-update", line 39, in <module>
nfldb.update.run(**vars(args))
File "/usr/local/lib/python2.7/dist-packages/nfldb/update.py", line 535, in run
doit()
File "/usr/local/lib/python2.7/dist-packages/nfldb/update.py", line 525, in doit
update_games(db, batch_size=batch_size)
File "/usr/local/lib/python2.7/dist-packages/nfldb/update.py", line 397, in update_games
bulk_insert_game_data(cursor, scheduled, batch_size=batch_size)
File "/usr/local/lib/python2.7/dist-packages/nfldb/update.py", line 221, in bulk_insert_game_data
do()
File "/usr/local/lib/python2.7/dist-packages/nfldb/update.py", line 188, in do
nfldb.db._big_insert(cursor, table, bulk[table])
File "/usr/local/lib/python2.7/dist-packages/nfldb/db.py", line 356, in _big_insert
% (table, insert_fields, values))
File "/usr/local/lib/python2.7/dist-packages/psycopg2/extras.py", line 223, in execute
return super(RealDictCursor, self).execute(query, vars)
psycopg2.IntegrityError: insert or update on table "play" violates foreign key constraint "play_pos_team_fkey"
DETAIL: Key (pos_team)=(JAX) is not present in table "team".
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 27 (1 by maintainers)
I hope to have this fixed before the next game.
I think the best thing to do is to settle on
JAC/JAX, and do the translation insidenflgamewhen the JSON is parsed. On the next update, I’ll include a DB migration that syncs the entire database with the correct team name (something similar to what @mlloyd5 did manually).Ok so here’s my workaround. I reset my install, but I didn’t like the idea of keeping that inserted row in the teams table so I changed all occurrences of ‘JAX’ in the database to ‘JAC’ and then deleted the row from the teams table. Queries below: Run on the database:
insert into team values ('JAX','Jacksonville','Jaguars')Runnfldb-updateIf you’d like, you can verify that only the
playtable needs to be updated:Update
playtable:UPDATE play SET pos_team = 'JAC' WHERE pos_team = 'JAX'Delete ‘JAX’ value from
team:DELETE FROM team WHERE team_id = 'JAX'@vhaar1 I did the following as a work-around.
Here’s the script I’m using. Hopefully @BurntSushi finds the time for a permanent fix soon!
I’m running ubuntu and saved it as
~/.local/bin/nfldb-update-script.shMake it executuable withchmod +x nfldb-update-script.shand then instead of runningnfldb-updaterunnfldb-update-script.shfrom anywhere.Looking forward to next season… Will the JAX/JAC issue be resolved? Will the Rams issue be resolved? Will the Raiders move to Las Vegas create a new issue? (This isn’t a dig at BurntSushi but rather questions about GameCenter) For one segment of my program that reports score changes, penalties etc. of games in progress I’d like to run nfldb-update at a 30 second interval:
C:\Python27\scripts python nfldb-update --Interval 30But would I need to also run theINSERT into team values('JAX','Jacksonville', 'Jaguars');andUPDATE play SET pos_team = 'JAC' WHERE pos_team = 'JAX';DELETE FROM team WHERE team_id = 'JAX'with each update? And can I incorporate these lines into the nfldb-update script if so?KennySushi and mlloyd5, thank you very much for your help. My postgres and python programming abilities are lacking. I used them to retrieve the info from the nfldb database and import the scores/stats into an excel vba program that I spent about 6 months developing and was working flawlessly until the JAC/JAZ episode. My excel program does an nfldb upgrade at the beginning of the season, at the transition from pre-season to regular and to post-season. It also does an upgrade once per month during the regular season so I had to include your Insert, PLAY, UPDATE and JAX DELETE each time the upgrade is performed. So far, my program is working well due to your help.
What I did was create 3 different scripts and save them in the
Python27folder:Create a script named
Insert_JAX.sqlwith the following code:INSERT into team values('JAX','Jacksonville', 'Jaguars');Then create a script named
NewDB.pywith the following code:import osos.chdir("c:\\Python27\\Scripts")execfile("nfldb-update")Then create another script named
Delete_JAX.sql:UPDATE play SET pos_team = 'JAC' WHERE pos_team = 'JAX';DELETE FROM team WHERE team_id = 'JAX'My program code runs as thus:
psql -U nfldb -f C:\Python27\Insert_JAX.sqlPython C:\Python27\NewDB.pypsql -U nfldb -f C:\Python27\Delete_JAX.sqlThis seems to be the best fix for now and I suspect it wont hurt anything to keep the code if/when a fix is implemented. One note is that this script will need to be re-run any time you upgrade nfldb
the JAX insert (
insert into team values ('JAX','Jacksonville','Jaguars')) does the trick. A better solution would be for the update script to check if team’s (or other necessary ref data) don’t exist and add them prior to inserting transactional data.It might be up to the end user whether to update older records to match or to query by name (e.g.
name = 'Jaguars') to get both sets of data. All depends on your use case I suppose.I used the work around below and it’s been working fine since then. I assume at some point I’ll have to roll back. IIRC you must navigate to the folder where “psql” is located (usually the PostgreSQL folder) via cmd.exe and then run the insert statement via:
I seem to get this error with LA as well. Just notifying.
@kennysushi I executed the insert statement after logging-in on the server via the psql command:
That worked great. Thanks.