fails to display table with foreign keys
See original GitHub issueUsing the latest version from pip, I have the following issue:
When I click on a table that contains a foreign key, an Internal Server Error is caused with the following Traceback:
[2018-04-26 10:56:55,863] ERROR in app: Exception on /expression/ [GET]
Traceback (most recent call last):
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/_compat.py", line 33,in reraise
raise value
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/sqlite_web/sqlite_web.py", line 201, in inner
return fn(table, *args, **kwargs)
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/sqlite_web/sqlite_web.py", line 217, in table_structure
ds_table = dataset[table]
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/playhouse/dataset.py", line63, in __getitem__
self.update_cache(table)
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/playhouse/dataset.py", line92, in update_cache
literal_column_names=True)
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/playhouse/reflection.py", line 598, in generate_models
literal_column_names=literal_column_names)
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/playhouse/reflection.py", line 586, in introspect
related_name=related_names.get(src))
File "/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/playhouse/reflection.py", line 120, in set_foreign_key
self.rel_model = model_names[foreign_key.dest_table]
KeyError: 'sample'
The SQL of the table looks like
create table sample (sample varchar(80)
, patient varchar(80)
, cohort varchar(10)
, sample_type varchar(4)
, PRIMARY KEY (sample)
, FOREIGN KEY (cohort) references cohort(cohort)
, FOREIGN KEY (sample_type) references sample_type(sample_type))
The SQL of the referenced tables like
create table cohort (cohort varchar(10)
, name text
, PRIMARY KEY (cohort));
create table sample_type (numeric_code varchar(2)
, sample_type varchar(8)
, definition text
, PRIMARY KEY (sample_type)
, UNIQUE(numeric_code))
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
3 common foreign key mistakes (and how to avoid them)
Dangling foreign keys 3. Not creating foreign key indexes Bonus: Not using foreign keys Key takeaway: think before you CREATE TABLE.
Read more >Showing full MySQL foreign key errors - Stitcher.io
In case of a foreign key error when creating or altering a table, MySQL doesn't show the full message. You can read the...
Read more >Bogus foreign key constraint fail - mysql - Stack Overflow
The innodb internal data dictionary is out of sync with the mysql one. You can see which table it was (one of them,...
Read more >MySQL - Check or Not Foreign Key Constraints - SQLines
As an alternative, you can firstly create tables without foreign key constraints, load data and then create foreign keys using ALTER TABLE statements....
Read more >13.1.20.5 FOREIGN KEY Constraints - MySQL :: Developer Zone
InnoDB does not currently support foreign keys for tables with user-defined partitioning. This includes both parent and child tables.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The fix involved ensuring that dependent tables are specified when updating the cache with a newly-added table. This is fixed in peewee master branch. I will push a new release (will be 3.3.4) shortly.
Traceback:
After restarting the application, the table loads up fine, so this looks to be a cache-invalidation type of issue.