{"id":23960873,"url":"https://github.com/pawel-slowik/sql-non-unique-fk","last_synced_at":"2026-06-22T09:31:20.057Z","repository":{"id":111444853,"uuid":"163728561","full_name":"pawel-slowik/sql-non-unique-fk","owner":"pawel-slowik","description":"Inspect a SQL database to find foreign keys referring to columns that do not have a unique key","archived":false,"fork":false,"pushed_at":"2026-02-25T21:47:52.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-26T00:38:59.206Z","etag":null,"topics":["sql","sqlalchemy","utility"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pawel-slowik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-01-01T10:20:10.000Z","updated_at":"2026-02-25T21:47:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"267ae05f-0bc4-46b1-a921-3860cf1840fc","html_url":"https://github.com/pawel-slowik/sql-non-unique-fk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pawel-slowik/sql-non-unique-fk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawel-slowik%2Fsql-non-unique-fk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawel-slowik%2Fsql-non-unique-fk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawel-slowik%2Fsql-non-unique-fk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawel-slowik%2Fsql-non-unique-fk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pawel-slowik","download_url":"https://codeload.github.com/pawel-slowik/sql-non-unique-fk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawel-slowik%2Fsql-non-unique-fk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34643500,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sql","sqlalchemy","utility"],"created_at":"2025-01-06T19:57:26.570Z","updated_at":"2026-06-22T09:31:20.051Z","avatar_url":"https://github.com/pawel-slowik.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build Status][build-badge]\n[![Coverage][coverage-badge]][coverage-url]\n\n[build-badge]: https://github.com/pawel-slowik/sql-non-unique-fk/workflows/tests/badge.svg\n[coverage-badge]: https://codecov.io/gh/pawel-slowik/sql-non-unique-fk/branch/master/graph/badge.svg\n[coverage-url]: https://codecov.io/gh/pawel-slowik/sql-non-unique-fk\n\nThis script inspects a SQL database to find foreign keys referring to columns\nthat do not have a unique key. For example:\n\n\tCREATE TABLE parent (\n\t\tid INT\n\t);\n\n\tCREATE TABLE child (\n\t\tparent_id INT,\n\t\tFOREIGN KEY(parent_id) REFERENCES parent(id)\n\t);\n\nHere, the key declared on the `parent_id` column refers to a non-unique column.\nThis, [according to MySQL documentation][mysql-doc], may cause undefined behavior:\n\n\u003e The handling of foreign key references to nonunique keys or keys that contain\n\u003e NULL values is not well defined for operations such as UPDATE or DELETE\n\u003e CASCADE. You are advised to use foreign keys that reference only UNIQUE\n\u003e (including PRIMARY) and NOT NULL keys.\n\nNote: this particular example is rather obvious and somewhat contrived, but there\nmay be cases where the problematic key is harder to find (for example, when the\nunique key on the referred column evolved into a multi-column key, but analogous\nchange was not applied to the child table).\n\n[mysql-doc]: https://dev.mysql.com/doc/mysql-reslimits-excerpt/8.0/en/ansi-diff-foreign-keys.html\n\n## Installation\n\nClone this repository and make sure you have Python 3.x and\n[SQLAlchemy][sqlalchemy] installed:\n\n\tpip3 install -r requirements.txt\n\nYou will also need to install a [SQLAlchemy dialect][sqlalchemy-dialect]\nsuitable for your database:\n\n\tpip3 install mysqlclient\n\n[sqlalchemy]:https://www.sqlalchemy.org/\n[sqlalchemy-dialect]:https://docs.sqlalchemy.org/en/latest/dialects/index.html\n\nOn Debian 13 / trixie you can use distribution provided packages, e.g.:\n\n\tsudo apt-get install python3-sqlalchemy python3-mysqldb\n\n## Example usage\n\n\t~/path/sqlnufk.py mysql://bar_user:barP455word@host.bar/bar_database\n\nFor MySQL databases you can also use an option group name instead of the\ndatabase URL. This works similar to the `--defaults-group-suffix` parameter of\nthe `mysql` command line utility. For example, if you have the following\noptions saved in your `~/.my.cnf` file:\n\n\t[client_foo]\n\thost=host.bar\n\tdatabase=bar_database\n\tuser=bar_user\n\tpassword=barP455word\n\nthen you can run:\n\n\t~/path/sqlnufk.py foo\n\nThe script will exit with code 0 if no problematic foreign keys are found.\nIf problematic keys are found, they will be printed on standard output and the\nscript will exit with code 64. Any other exit code means that the script could\nnot check the keys (connection problem, driver / dialect not installed, invalid\nURL etc.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawel-slowik%2Fsql-non-unique-fk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpawel-slowik%2Fsql-non-unique-fk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawel-slowik%2Fsql-non-unique-fk/lists"}